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

@@ -1499,19 +1499,22 @@ func (s *Server) handleCreateMyAssessmentAttemptRequest(args [0]string, argsEsca
// `additional_practice_pending` for the additional one, and its deadline has not passed. Otherwise the
// server answers 409 state_conflict.
//
// Availability. When code practice is not enabled on this server, the server answers 503
// service_unavailable and stores nothing.
// Limits. Debug runs are bounded by a per-candidate rate limit and by one unfinished run per practice;
// either answers 429 rate_limited with Retry-After. The sandbox queue holds one running and ten
// waiting runs and submissions together; when it is full the server answers 503 service_unavailable
// with Retry-After and stores nothing. When code practice is not enabled on this server, the server
// answers 503 service_unavailable without Retry-After and stores nothing.
//
// Repeats. A retry with the same Idempotency-Key and body within 24 hours returns the stored run in
// its current state with 202, without starting another run. A different body with the same key answers
// 422 idempotency_key_reused. Refusals (400, 404, 409, 503) are not stored under the key and are
// 422 idempotency_key_reused. Refusals (400, 404, 409, 429, 503) are not stored under the key and are
// evaluated again.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden), the availability of code practice (503), the Idempotency-Key (422,
// replay), the attempt and the practice (404 not_found for an unknown attempt or item, or one of
// another candidate), the state (409), then the solution against the item (400 with a pointer such as
// `/language` or `/source_code`).
// another candidate), the state (409), the solution against the item (400 with a pointer such as
// `/language` or `/source_code`), the limits (429), then the queue (503).
//
// POST /api/v1/me/assessment-attempts/{attempt_id}/practice-runs
func (s *Server) handleCreateMyAssessmentPracticeRunRequest(args [1]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) {
@@ -778,6 +778,38 @@ func encodeCreateMyAssessmentPracticeRunResponse(response CreateMyAssessmentPrac
return nil
case *TooManyRequestsHeaders:
w.Header().Set("Content-Type", "application/problem+json")
w.Header().Set("Access-Control-Expose-Headers", "Retry-After")
// Encoding response headers.
{
h := uri.NewHeaderEncoder(w.Header())
// Encode "Retry-After" header.
{
cfg := uri.HeaderParameterEncodingConfig{
Name: "Retry-After",
Explode: false,
}
if err := h.EncodeParam(cfg, func(e uri.Encoder) error {
if val, ok := response.RetryAfter.Get(); ok {
return e.EncodeValue(conv.Int32ToString(val))
}
return nil
}); err != nil {
return errors.Wrap(err, "encode Retry-After header")
}
}
}
w.WriteHeader(429)
e := new(jx.Encoder)
response.Response.Encode(e)
if _, err := e.WriteTo(w); err != nil {
return errors.Wrap(err, "write")
}
return nil
case *ServiceUnavailableHeaders:
w.Header().Set("Content-Type", "application/problem+json")
w.Header().Set("Access-Control-Expose-Headers", "Retry-After")
@@ -32842,6 +32842,7 @@ func (*TooManyRequestsHeaders) cancelMyInvitationRes() {}
func (*TooManyRequestsHeaders) confirmEmailByCodeRes() {}
func (*TooManyRequestsHeaders) confirmEmailRes() {}
func (*TooManyRequestsHeaders) createMyAssessmentAttemptRes() {}
func (*TooManyRequestsHeaders) createMyAssessmentPracticeRunRes() {}
func (*TooManyRequestsHeaders) createMySupportCaseRes() {}
func (*TooManyRequestsHeaders) createOrganizationInvitationRes() {}
func (*TooManyRequestsHeaders) createOrganizationNeedRes() {}
@@ -247,19 +247,22 @@ type Handler interface {
// `additional_practice_pending` for the additional one, and its deadline has not passed. Otherwise the
// server answers 409 state_conflict.
//
// Availability. When code practice is not enabled on this server, the server answers 503
// service_unavailable and stores nothing.
// Limits. Debug runs are bounded by a per-candidate rate limit and by one unfinished run per practice;
// either answers 429 rate_limited with Retry-After. The sandbox queue holds one running and ten
// waiting runs and submissions together; when it is full the server answers 503 service_unavailable
// with Retry-After and stores nothing. When code practice is not enabled on this server, the server
// answers 503 service_unavailable without Retry-After and stores nothing.
//
// Repeats. A retry with the same Idempotency-Key and body within 24 hours returns the stored run in
// its current state with 202, without starting another run. A different body with the same key answers
// 422 idempotency_key_reused. Refusals (400, 404, 409, 503) are not stored under the key and are
// 422 idempotency_key_reused. Refusals (400, 404, 409, 429, 503) are not stored under the key and are
// evaluated again.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden), the availability of code practice (503), the Idempotency-Key (422,
// replay), the attempt and the practice (404 not_found for an unknown attempt or item, or one of
// another candidate), the state (409), then the solution against the item (400 with a pointer such as
// `/language` or `/source_code`).
// another candidate), the state (409), the solution against the item (400 with a pointer such as
// `/language` or `/source_code`), the limits (429), then the queue (503).
//
// POST /api/v1/me/assessment-attempts/{attempt_id}/practice-runs
CreateMyAssessmentPracticeRun(ctx context.Context, req *PracticeRunCreate, params CreateMyAssessmentPracticeRunParams) (CreateMyAssessmentPracticeRunRes, error)
@@ -270,19 +270,22 @@ func (UnimplementedHandler) CreateMyAssessmentAttempt(ctx context.Context, req A
// `additional_practice_pending` for the additional one, and its deadline has not passed. Otherwise the
// server answers 409 state_conflict.
//
// Availability. When code practice is not enabled on this server, the server answers 503
// service_unavailable and stores nothing.
// Limits. Debug runs are bounded by a per-candidate rate limit and by one unfinished run per practice;
// either answers 429 rate_limited with Retry-After. The sandbox queue holds one running and ten
// waiting runs and submissions together; when it is full the server answers 503 service_unavailable
// with Retry-After and stores nothing. When code practice is not enabled on this server, the server
// answers 503 service_unavailable without Retry-After and stores nothing.
//
// Repeats. A retry with the same Idempotency-Key and body within 24 hours returns the stored run in
// its current state with 202, without starting another run. A different body with the same key answers
// 422 idempotency_key_reused. Refusals (400, 404, 409, 503) are not stored under the key and are
// 422 idempotency_key_reused. Refusals (400, 404, 409, 429, 503) are not stored under the key and are
// evaluated again.
//
// Order of checks: session (401), CSRF and Origin (403 csrf_check_failed), request validation (400),
// account scenario (403 forbidden), the availability of code practice (503), the Idempotency-Key (422,
// replay), the attempt and the practice (404 not_found for an unknown attempt or item, or one of
// another candidate), the state (409), then the solution against the item (400 with a pointer such as
// `/language` or `/source_code`).
// another candidate), the state (409), the solution against the item (400 with a pointer such as
// `/language` or `/source_code`), the limits (429), then the queue (503).
//
// POST /api/v1/me/assessment-attempts/{attempt_id}/practice-runs
func (UnimplementedHandler) CreateMyAssessmentPracticeRun(ctx context.Context, req *PracticeRunCreate, params CreateMyAssessmentPracticeRunParams) (r CreateMyAssessmentPracticeRunRes, _ error) {