feat: let asynq retry submit request if it's internal error

This commit is contained in:
Paul Pan 2024-01-07 00:45:16 +08:00
parent 7be0379e30
commit 7446ac6d23
Signed by: Paul
GPG Key ID: D639BDF5BA578AF4

View File

@ -44,26 +44,31 @@ func (h *handler) Judge(_ context.Context, t *asynq.Task) error {
if !h.runnerService.ProblemExists(p.ProblemVersionID) {
url, status := h.storageService.Get(p.StorageKey, time.Second*60*5)
if status != e.Success {
return e.InternalError, 0, systemError
return status, 0, systemError
}
_, status = h.runnerService.NewProblem(p.ProblemVersionID, url, false)
if status != e.Success {
return e.InternalError, 0, systemError
return status, 0, systemError
}
}
// 3. compile
compileResult, status := h.runnerService.Compile(p.ProblemVersionID, user, p.Submission.Language)
if status != e.Success {
return e.InternalError, 0, compileResult
return status, 0, compileResult
}
// 4. run and judge
result, point, status := h.runnerService.RunAndJudge(p.ProblemVersionID, user, p.Submission.Language)
return utils.If(status != e.Success, e.InternalError, e.Success), point, result
return status, point, result
}()
if status == e.InternalError {
// notice asynq to retry
return fmt.Errorf("internal error, ctx: %v", ctx)
}
h.taskService.SubmitUpdate(&model.SubmitUpdatePayload{
Status: status,
SubmissionID: p.Submission.ID,