diff --git a/.env.example b/.env.example index e2bd624..1cd4e8e 100644 --- a/.env.example +++ b/.env.example @@ -253,6 +253,11 @@ USACO_WEBHOOK_SECRET= # 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. 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). # Claude cannot take audio, so this OpenAI key transcribes it (whisper-1, # about $0.006 a minute). Blank turns reviews off. diff --git a/docker-compose.yml b/docker-compose.yml index defaeb3..88e30dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -568,10 +568,17 @@ services: # 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 # 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 - # that clone, so deleting it is safe; the image runs as uid 1000, so the + # the blank-key case blanks the rest). USACO_CLAUDE_MONTHLY_BUDGET (dollars, + # 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. # + # 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 # login: visitors see solved problems, and AUTH_VALIDATE_URL decides who # is the admin from the visitor's cookies. @@ -579,6 +586,7 @@ services: image: adam-french.co.uk/adamf/usaco:${USACO_IMAGE_TAG:-latest} container_name: usaco restart: always + stop_grace_period: 6m depends_on: - gitea - usaco-runner @@ -592,6 +600,7 @@ services: - AUTH_VALIDATE_URL=http://${BACKEND_HOST}:${BACKEND_PORT}/auth/validate-admin - CLAUDE_API_KEY=${CLAUDE_API_KEY:-} - CLAUDE_MODEL=${USACO_CLAUDE_MODEL:-} + - CLAUDE_MONTHLY_BUDGET=${USACO_CLAUDE_MONTHLY_BUDGET:-} - TRANSCRIBE_API_KEY=${USACO_OPENAI_API_KEY:-} - S3_ACCESS_KEY_ID=${USACO_S3_ACCESS_KEY_ID:-} - S3_SECRET_ACCESS_KEY=${USACO_S3_SECRET_ACCESS_KEY:-}