feat(practice): store code submissions and practice states apart from attempts
This commit is contained in:
1 parent
d5e169e71b
commit
51770eea6c
61 files changed
+8584
-135
No files matched your search
@@ -0,0 +1,84 @@
|
||||
package outbound
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrAssessmentPracticeNotFound reports a practice that is unknown or
|
||||
// not a practice of the owner's attempt.
|
||||
ErrAssessmentPracticeNotFound = errors.New("assessment practice not found")
|
||||
// ErrPracticeRunNotFound reports a debug run that is unknown or not a
|
||||
// run of the owner's attempt.
|
||||
ErrPracticeRunNotFound = errors.New("practice run not found")
|
||||
)
|
||||
|
||||
// PracticeAttemptLock is what a practice command reads about its attempt
|
||||
// under the share lock.
|
||||
type PracticeAttemptLock struct {
|
||||
State domain.AssessmentAttemptState
|
||||
ExpiresAt time.Time
|
||||
// DatabaseTime is read after the lock was granted.
|
||||
DatabaseTime time.Time
|
||||
}
|
||||
|
||||
// PracticeSubmissionReplay identifies the stored submission that a replayed
|
||||
// request returns.
|
||||
type PracticeSubmissionReplay struct {
|
||||
ID uuid.UUID
|
||||
PracticeID uuid.UUID
|
||||
Mode domain.PracticeSubmissionMode
|
||||
}
|
||||
|
||||
// PracticeFinalSolution identifies the latest final submission of a practice
|
||||
// without its source.
|
||||
type PracticeFinalSolution struct {
|
||||
SubmissionID uuid.UUID
|
||||
Language domain.TaskLanguageCode
|
||||
SourceDigest domain.PracticeSourceDigest
|
||||
}
|
||||
|
||||
// AssessmentPracticeRepositories groups the practice repositories of a unit
|
||||
// of work.
|
||||
type AssessmentPracticeRepositories interface {
|
||||
AssessmentPractices() AssessmentPracticeRepository
|
||||
}
|
||||
|
||||
// AssessmentPracticeRepository keeps the practice items of attempts, their
|
||||
// submissions, and the execution jobs of the submissions, separately from the
|
||||
// attempt snapshot and the result. Every read is scoped by the owner, so an
|
||||
// identifier of another candidate reads as not found.
|
||||
type AssessmentPracticeRepository interface {
|
||||
// Create stores a new practice of an attempt in the not_started state.
|
||||
// The attempt flow that serves practice items calls it.
|
||||
Create(ctx context.Context, practice domain.AssessmentPractice) error
|
||||
// LockAttempt locks the owner's attempt in share mode and reads its
|
||||
// state, deadline, and the database time. An unknown or foreign attempt
|
||||
// returns ErrAssessmentAttemptNotFound.
|
||||
LockAttempt(ctx context.Context, userID uuid.UUID, attemptID domain.AssessmentAttemptID) (PracticeAttemptLock, error)
|
||||
// LockPractice locks one practice of the owner's attempt for a state
|
||||
// change. An unknown or foreign practice returns
|
||||
// ErrAssessmentPracticeNotFound.
|
||||
LockPractice(ctx context.Context, userID uuid.UUID, attemptID domain.AssessmentAttemptID, practiceID uuid.UUID) (domain.AssessmentPractice, error)
|
||||
// SaveState stores the status, failure reason, and submission time of a
|
||||
// locked practice.
|
||||
SaveState(ctx context.Context, practice domain.AssessmentPractice, updatedAt time.Time) error
|
||||
// FindByScope returns the latest submission of the owner stored under
|
||||
// the idempotency scope, if any.
|
||||
FindByScope(ctx context.Context, userID uuid.UUID, scope [IdempotencyDigestSize]byte) (PracticeSubmissionReplay, bool, error)
|
||||
// LatestFinal returns the latest final submission of a practice, if any.
|
||||
LatestFinal(ctx context.Context, practiceID uuid.UUID) (PracticeFinalSolution, bool, error)
|
||||
// Submit stores a submission under the idempotency scope and queues its
|
||||
// execution job in the same transaction.
|
||||
Submit(ctx context.Context, submission domain.PracticeSubmission, scope [IdempotencyDigestSize]byte) error
|
||||
// GetRun reads a debug run of the owner's attempt with the state of its
|
||||
// job. It never returns a final submission; an unknown, foreign, or final
|
||||
// submission returns ErrPracticeRunNotFound.
|
||||
GetRun(ctx context.Context, userID uuid.UUID, attemptID domain.AssessmentAttemptID, runID uuid.UUID) (domain.PracticeRunView, error)
|
||||
}
|
||||
@@ -74,6 +74,7 @@ type UnitOfWork interface {
|
||||
AssessmentAttemptRepositories
|
||||
AssessmentSignalRepositories
|
||||
AssessmentSignalNoticeRepositories
|
||||
AssessmentPracticeRepositories
|
||||
SupportCaseRepositories
|
||||
Policies() PolicyRepository
|
||||
Deliveries() DeliveryRepository
|
||||
|
||||
Reference in new issue
Block a user