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
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"lincodex/backend/internal/adapter/secondary/postgres/sqlc"
|
||||
@@ -153,8 +154,16 @@ func (store *PracticeJobStore) Requeue(ctx context.Context, job outbound.Claimed
|
||||
return updated == 1, nil
|
||||
}
|
||||
|
||||
func (store *PracticeJobStore) Complete(ctx context.Context, job outbound.ClaimedPracticeJob, result domain.PracticeRunResult) (bool, error) {
|
||||
func (store *PracticeJobStore) Complete(
|
||||
ctx context.Context,
|
||||
job outbound.ClaimedPracticeJob,
|
||||
runnerRunID uuid.UUID,
|
||||
result domain.PracticeRunResult,
|
||||
) (bool, error) {
|
||||
const location = "PracticeJobStore.Complete"
|
||||
if runnerRunID == uuid.Nil {
|
||||
return false, errors.New(location + " - runner run ID must be set")
|
||||
}
|
||||
if err := result.Validate(); err != nil {
|
||||
return false, fmt.Errorf("%s - validate result: %w", location, err)
|
||||
}
|
||||
@@ -177,7 +186,7 @@ func (store *PracticeJobStore) Complete(ctx context.Context, job outbound.Claime
|
||||
if stored != 1 {
|
||||
return outbound.ErrPracticeResultExists
|
||||
}
|
||||
if err := finishPracticeJob(ctx, queries, job, practiceJobFinished, ""); err != nil {
|
||||
if err := finishPracticeJob(ctx, queries, job, practiceJobFinished, "", runnerRunID); err != nil {
|
||||
return err
|
||||
}
|
||||
if mode == domain.PracticeModeFinal {
|
||||
@@ -205,7 +214,7 @@ func (store *PracticeJobStore) Fail(ctx context.Context, job outbound.ClaimedPra
|
||||
if err != nil || !locked {
|
||||
return err
|
||||
}
|
||||
if err := finishPracticeJob(ctx, queries, job, practiceJobFailed, class); err != nil {
|
||||
if err := finishPracticeJob(ctx, queries, job, practiceJobFailed, class, uuid.Nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if mode == domain.PracticeModeFinal {
|
||||
@@ -247,9 +256,15 @@ func finishPracticeJob(
|
||||
job outbound.ClaimedPracticeJob,
|
||||
state string,
|
||||
class outbound.PracticeJobErrorClass,
|
||||
runnerRunID uuid.UUID,
|
||||
) error {
|
||||
// A failed job has no run ID: uuid.Nil stores NULL.
|
||||
var runnerRun pgtype.UUID
|
||||
if runnerRunID != uuid.Nil {
|
||||
runnerRun = pgUUID(runnerRunID)
|
||||
}
|
||||
finished, err := queries.FinishAssessmentPracticeJob(ctx, sqlc.FinishAssessmentPracticeJobParams{
|
||||
State: state, ErrorClass: pgOptionalText(string(class)), SubmissionID: pgUUID(job.SubmissionID),
|
||||
State: state, ErrorClass: pgOptionalText(string(class)), RunnerRunID: runnerRun, SubmissionID: pgUUID(job.SubmissionID),
|
||||
LeaseOwner: pgUUID(job.LeaseOwner), StartedAt: timestamp(job.StartedAt),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user