feat(practice): queue practice runs with one running and ten waiting

This commit is contained in:
shira committed 2026-10-11 15:01:07 +03:00
1 parent 51770eea6c
commit 754c745fba
40 files changed
+3040 -70

No files matched your search

+20 -1
View File
@@ -895,7 +895,7 @@ Checked on 2026-10-11 with the runner at commit `dcf03cb861e2` plus two fixes. T
## Code runner client
The backend calls the own code runner (see [the runner](ARCHITECTURE.md#code-runner)) through the `CodeRunner` port. It is off unless `CODE_RUNNER_URL` is set: the backend then selects a disabled runner, logs `code runner selected` with `enabled=false` and a warning, and reports every request as unavailable without running or grading anything. `.env.example` and the Compose file pass every variable below as empty, so a default stack never contacts a runner. Nothing in this build calls the port yet; the settings are validated at startup and the TLS client is built (no network call), so a wrong value fails fast.
The backend calls the own code runner (see [the runner](ARCHITECTURE.md#code-runner)) through the `CodeRunner` port. It is off unless `CODE_RUNNER_URL` is set: the backend then selects a disabled runner, logs `code runner selected` with `enabled=false` and a warning, and reports every request as unavailable without running or grading anything. `.env.example` and the Compose file pass every variable below as empty, so a default stack never contacts a runner. Only the practice queue worker calls the port (see [below](#practice-queue-and-debug-run-limits)); the settings are validated at startup and the TLS client is built (no network call), so a wrong value fails fast.
When `CODE_RUNNER_URL` is empty, no other `CODE_RUNNER_*` variable may be set: the backend refuses to start rather than ignore a token. Errors name the setting and never print its value; the startup log names neither the URL nor a secret.
@@ -919,6 +919,25 @@ Checking a real runner. The unit tests run against a local protocol stand-in. To
`CODE_RUNNER_SERVER_NAME` is honored too. The target stops with an error when the three variables are unset, and the same tests are skipped by a plain `go test` because they run only when `CODE_RUNNER_LIVE_URL` is set. A pass proves that the client, the TLS settings, the token, and the runner agree on the protocol and that the runner grades the fixed programs as expected; it does not replace the A16 suite.
### Practice queue and debug run limits
With a code runner configured, the backend runs the practice queue worker as a goroutine next to the HTTP servers (design in [ARCHITECTURE.md](ARCHITECTURE.md#practice-queue)). It needs `DATABASE_URL`, uses its own PostgreSQL pool of at most two connections, and does not start without `CODE_RUNNER_URL`; queued jobs then wait in the database. One job runs at a time across all backend instances and ten more may wait; the limits are product rules, not settings. At shutdown the worker gives its job back at once; a killed backend leaves the job running until its lease expires, and then another instance or the restarted one takes it over without starting a second run. Compose passes none of the settings below, so the stack uses the defaults; to change one, add it to the backend `environment` in `deploy/docker/docker-compose.yml`. They are validated at startup even without a runner.
| Variable | Default | Meaning |
| --- | --- | --- |
| `PRACTICE_RUNS_PER_MINUTE` | `6` | New debug runs of one candidate per minute, from 1 to 600 (Redis limiter). Beyond it the run answers 429 with `Retry-After`. |
| `PRACTICE_RUNS_PER_HOUR` | `60` | New debug runs of one candidate per hour, from `PRACTICE_RUNS_PER_MINUTE` to 36000. |
| `PRACTICE_POLL_INTERVAL` | `1s` | Wait between two reads of a running run and after a pass that found nothing to run, from 10ms to 30s. |
| `PRACTICE_JOB_LEASE` | `30s` | How long a claimed job belongs to one worker without a renewal; every poll renews it. Above `CODE_RUNNER_REQUEST_TIMEOUT` plus `PRACTICE_POLL_INTERVAL`, at most 10m. A crashed worker delays its job by at most this long. |
| `PRACTICE_JOB_MAX_ATTEMPTS` | `5` | Failed tries and expired leases of a job before it fails without a verdict, from 1 to 100. A busy runner and a shutdown do not count. |
Leases are compared with the backend clock, so keep the hosts of all backend instances synchronized with NTP. A job that failed is `failed` in `assessment_practice_jobs` with `last_error_class` `runner_unavailable`, `runner_infrastructure_failure`, `invalid_request`, `run_timeout`, or `lease_expired`; the worker logs it at error level as `practice job failed in the infrastructure; nothing was graded`. The candidate can submit again; a failed job is never retried by an operator. Queue metrics are not implemented yet; count unfinished jobs with psql:
SELECT state, mode, count(*), min(available_at)
FROM assessment_practice_jobs
WHERE state IN ('queued', 'running')
GROUP BY state, mode;
## Services and images
Container images use moving `latest` or `alpine` tags where the upstream publishes them. Check the current Compose references when updating the stack. These tags can move; the [release manifest](#release-manifest) records the actual image digests of a release. An SBOM is not produced yet. Application dependency lockfiles remain checked in separately.