usaco: let running jobs finish on stop, add a Claude budget
Test and deploy / test (push) Successful in 1m20s
Test and deploy / deploy (push) Successful in 1m12s

The site now waits up to 5 minutes on SIGTERM for running Claude jobs, so
stop_grace_period must be longer than Docker's 10s default.
USACO_CLAUDE_MONTHLY_BUDGET caps its estimated monthly Claude spend.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-23 22:10:08 +01:00
co-authored by Claude Opus 5.5
parent acf21c69c2
commit 263e16b70d
2 changed files with 16 additions and 2 deletions
+5
View File
@@ -253,6 +253,11 @@ USACO_WEBHOOK_SECRET=
# extraction. Blank means claude-opus-5-5. The key is CLAUDE_API_KEY above; # extraction. Blank means claude-opus-5-5. The key is CLAUDE_API_KEY above;
# without it the button is off and the rest of the site works. # without it the button is off and the rest of the site works.
USACO_CLAUDE_MODEL= USACO_CLAUDE_MODEL=
# Monthly cap on the USACO site's estimated Claude spend, in dollars (e.g.
# 20). Once a calendar month (UTC) reaches it, new Explain/review/concept/
# evaluate jobs are refused until the 1st. Blank: no cap; the spend is still
# shown on the site's stats page to the admin.
USACO_CLAUDE_MONTHLY_BUDGET=
# Recording reviews (the admin uploads themselves explaining a solution). # Recording reviews (the admin uploads themselves explaining a solution).
# Claude cannot take audio, so this OpenAI key transcribes it (whisper-1, # Claude cannot take audio, so this OpenAI key transcribes it (whisper-1,
# about $0.006 a minute). Blank turns reviews off. # about $0.006 a minute). Blank turns reviews off.
+11 -2
View File
@@ -568,10 +568,17 @@ services:
# USACO_OPENAI_API_KEY to transcribe, and keep the audio in Garage's # USACO_OPENAI_API_KEY to transcribe, and keep the audio in Garage's
# private usaco-audio bucket when USACO_S3_* is set (the site refuses to # private usaco-audio bucket when USACO_S3_* is set (the site refuses to
# start with only some S3_* set, so all five go together or not at all: # start with only some S3_* set, so all five go together or not at all:
# the blank-key case blanks the rest). ./usaco-data holds only # the blank-key case blanks the rest). USACO_CLAUDE_MONTHLY_BUDGET (dollars,
# that clone, so deleting it is safe; the image runs as uid 1000, so the # blank for none) stops new Claude jobs once a month's estimated spend
# reaches it. ./usaco-data holds that clone, the background jobs' records
# and the Claude spend ledger; deleting it is safe (it re-clones) but loses
# any answer not yet committed. The image runs as uid 1000, so the
# directory must be owned by it. # directory must be owned by it.
# #
# On stop it lets running Claude jobs finish for up to SHUTDOWN_GRACE (5m
# by default) before exiting, so stop_grace_period must be longer than
# that, or Docker kills it mid-job.
#
# Same explicit `environment:` list as jobs. Like the tracker it has no # Same explicit `environment:` list as jobs. Like the tracker it has no
# login: visitors see solved problems, and AUTH_VALIDATE_URL decides who # login: visitors see solved problems, and AUTH_VALIDATE_URL decides who
# is the admin from the visitor's cookies. # is the admin from the visitor's cookies.
@@ -579,6 +586,7 @@ services:
image: adam-french.co.uk/adamf/usaco:${USACO_IMAGE_TAG:-latest} image: adam-french.co.uk/adamf/usaco:${USACO_IMAGE_TAG:-latest}
container_name: usaco container_name: usaco
restart: always restart: always
stop_grace_period: 6m
depends_on: depends_on:
- gitea - gitea
- usaco-runner - usaco-runner
@@ -592,6 +600,7 @@ services:
- AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin - AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin
- CLAUDE_API_KEY=${CLAUDE_API_KEY:-} - CLAUDE_API_KEY=${CLAUDE_API_KEY:-}
- CLAUDE_MODEL=${USACO_CLAUDE_MODEL:-} - CLAUDE_MODEL=${USACO_CLAUDE_MODEL:-}
- CLAUDE_MONTHLY_BUDGET=${USACO_CLAUDE_MONTHLY_BUDGET:-}
- TRANSCRIBE_API_KEY=${USACO_OPENAI_API_KEY:-} - TRANSCRIBE_API_KEY=${USACO_OPENAI_API_KEY:-}
- S3_ACCESS_KEY_ID=${USACO_S3_ACCESS_KEY_ID:-} - S3_ACCESS_KEY_ID=${USACO_S3_ACCESS_KEY_ID:-}
- S3_SECRET_ACCESS_KEY=${USACO_S3_SECRET_ACCESS_KEY:-} - S3_SECRET_ACCESS_KEY=${USACO_S3_SECRET_ACCESS_KEY:-}