feat(practice): run practice jobs on the code runner with one stored result per run
This commit is contained in:
1 parent
9385b2ddd4
commit
9344228e84
17 files changed
+1010
-35
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
"lincodex/backend/internal/port/outbound"
|
||||
)
|
||||
@@ -172,19 +174,23 @@ func (executor *Executor) runnerFailure(ctx context.Context, job outbound.Claime
|
||||
}
|
||||
|
||||
func (executor *Executor) complete(ctx context.Context, job outbound.ClaimedPracticeJob, status outbound.CodeRunStatus) (ExecutionOutcome, error) {
|
||||
if status.Result == nil {
|
||||
// A finished run names the runner run that the stored result belongs to;
|
||||
// a status without a result or a valid run ID is outside the contract.
|
||||
runnerRunID, idErr := uuid.Parse(status.RunID)
|
||||
if status.Result == nil || idErr != nil || runnerRunID == uuid.Nil {
|
||||
return executor.runnerFailure(ctx, job, outbound.ErrCodeRunnerBadResponse)
|
||||
}
|
||||
storeCtx, cancel := executor.storeContext(ctx)
|
||||
defer cancel()
|
||||
held, err := executor.store.Complete(storeCtx, job, runResult(*status.Result))
|
||||
held, err := executor.store.Complete(storeCtx, job, runnerRunID, runResult(*status.Result))
|
||||
switch {
|
||||
case err != nil:
|
||||
return "", fmt.Errorf("Executor.complete - store result: %w", err)
|
||||
case !held:
|
||||
return OutcomeLeaseLost, nil
|
||||
}
|
||||
executor.logger.Info("practice job finished", jobAttributes(job, slog.String("outcome", string(status.Result.Outcome)))...)
|
||||
executor.logger.Info("practice job finished", jobAttributes(job,
|
||||
slog.String("outcome", string(status.Result.Outcome)), slog.String("runner_run_id", runnerRunID.String()))...)
|
||||
return OutcomeFinished, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user