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,377 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: assessment_practice.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const findAssessmentPracticeSubmissionByScope = `-- name: FindAssessmentPracticeSubmissionByScope :one
|
||||
SELECT
|
||||
submission.id,
|
||||
submission.practice_id,
|
||||
submission.mode
|
||||
FROM assessment_practice_submissions AS submission
|
||||
WHERE
|
||||
submission.user_id = $1
|
||||
AND submission.idempotency_scope = $2
|
||||
ORDER BY submission.created_at DESC, submission.id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type FindAssessmentPracticeSubmissionByScopeParams struct {
|
||||
UserID pgtype.UUID
|
||||
IdempotencyScope []byte
|
||||
}
|
||||
|
||||
type FindAssessmentPracticeSubmissionByScopeRow struct {
|
||||
ID pgtype.UUID
|
||||
PracticeID pgtype.UUID
|
||||
Mode string
|
||||
}
|
||||
|
||||
// Finds the latest submission of the owner under an idempotency scope, which
|
||||
// a replay returns.
|
||||
func (q *Queries) FindAssessmentPracticeSubmissionByScope(ctx context.Context, arg FindAssessmentPracticeSubmissionByScopeParams) (FindAssessmentPracticeSubmissionByScopeRow, error) {
|
||||
row := q.db.QueryRow(ctx, findAssessmentPracticeSubmissionByScope, arg.UserID, arg.IdempotencyScope)
|
||||
var i FindAssessmentPracticeSubmissionByScopeRow
|
||||
err := row.Scan(&i.ID, &i.PracticeID, &i.Mode)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAssessmentPracticeRun = `-- name: GetAssessmentPracticeRun :one
|
||||
SELECT
|
||||
submission.id,
|
||||
submission.practice_id,
|
||||
submission.created_at,
|
||||
submission.result,
|
||||
job.state,
|
||||
job.finished_at
|
||||
FROM assessment_practice_submissions AS submission
|
||||
INNER JOIN assessment_practices AS practice ON submission.practice_id = practice.id
|
||||
INNER JOIN assessment_practice_jobs AS job ON submission.id = job.submission_id
|
||||
WHERE
|
||||
submission.id = $1
|
||||
AND submission.user_id = $2
|
||||
AND submission.mode = 'public'
|
||||
AND practice.attempt_id = $3
|
||||
`
|
||||
|
||||
type GetAssessmentPracticeRunParams struct {
|
||||
ID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
}
|
||||
|
||||
type GetAssessmentPracticeRunRow struct {
|
||||
ID pgtype.UUID
|
||||
PracticeID pgtype.UUID
|
||||
CreatedAt pgtype.Timestamptz
|
||||
Result []byte
|
||||
State string
|
||||
FinishedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Reads a debug run of the owner's attempt with the state of its job.
|
||||
func (q *Queries) GetAssessmentPracticeRun(ctx context.Context, arg GetAssessmentPracticeRunParams) (GetAssessmentPracticeRunRow, error) {
|
||||
row := q.db.QueryRow(ctx, getAssessmentPracticeRun, arg.ID, arg.UserID, arg.AttemptID)
|
||||
var i GetAssessmentPracticeRunRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PracticeID,
|
||||
&i.CreatedAt,
|
||||
&i.Result,
|
||||
&i.State,
|
||||
&i.FinishedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getLatestFinalPracticeSubmission = `-- name: GetLatestFinalPracticeSubmission :one
|
||||
SELECT
|
||||
submission.id,
|
||||
submission.language,
|
||||
submission.source_sha256
|
||||
FROM assessment_practice_submissions AS submission
|
||||
WHERE
|
||||
submission.practice_id = $1
|
||||
AND submission.mode = 'final'
|
||||
ORDER BY submission.created_at DESC, submission.id DESC
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
type GetLatestFinalPracticeSubmissionRow struct {
|
||||
ID pgtype.UUID
|
||||
Language string
|
||||
SourceSha256 []byte
|
||||
}
|
||||
|
||||
// The latest final submission of a practice: the solution the practice
|
||||
// state describes.
|
||||
func (q *Queries) GetLatestFinalPracticeSubmission(ctx context.Context, practiceID pgtype.UUID) (GetLatestFinalPracticeSubmissionRow, error) {
|
||||
row := q.db.QueryRow(ctx, getLatestFinalPracticeSubmission, practiceID)
|
||||
var i GetLatestFinalPracticeSubmissionRow
|
||||
err := row.Scan(&i.ID, &i.Language, &i.SourceSha256)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertAssessmentPractice = `-- name: InsertAssessmentPractice :exec
|
||||
INSERT INTO assessment_practices (
|
||||
id,
|
||||
attempt_id,
|
||||
user_id,
|
||||
kind,
|
||||
task,
|
||||
status,
|
||||
failure_reason,
|
||||
submitted_at,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
'not_started',
|
||||
NULL,
|
||||
NULL,
|
||||
$6,
|
||||
$6
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentPracticeParams struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Kind string
|
||||
Task []byte
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) InsertAssessmentPractice(ctx context.Context, arg InsertAssessmentPracticeParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentPractice,
|
||||
arg.ID,
|
||||
arg.AttemptID,
|
||||
arg.UserID,
|
||||
arg.Kind,
|
||||
arg.Task,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertAssessmentPracticeJob = `-- name: InsertAssessmentPracticeJob :exec
|
||||
INSERT INTO assessment_practice_jobs (
|
||||
submission_id,
|
||||
mode,
|
||||
state,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
'queued',
|
||||
$3,
|
||||
$3
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentPracticeJobParams struct {
|
||||
SubmissionID pgtype.UUID
|
||||
Mode string
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Queues the execution job of a submission in the transaction that stores
|
||||
// the submission.
|
||||
func (q *Queries) InsertAssessmentPracticeJob(ctx context.Context, arg InsertAssessmentPracticeJobParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentPracticeJob, arg.SubmissionID, arg.Mode, arg.CreatedAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertAssessmentPracticeSubmission = `-- name: InsertAssessmentPracticeSubmission :exec
|
||||
INSERT INTO assessment_practice_submissions (
|
||||
id,
|
||||
practice_id,
|
||||
user_id,
|
||||
mode,
|
||||
language,
|
||||
source,
|
||||
source_sha256,
|
||||
custom_tests,
|
||||
idempotency_scope,
|
||||
created_at
|
||||
) VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7,
|
||||
$8,
|
||||
$9,
|
||||
$10
|
||||
)
|
||||
`
|
||||
|
||||
type InsertAssessmentPracticeSubmissionParams struct {
|
||||
ID pgtype.UUID
|
||||
PracticeID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Mode string
|
||||
Language string
|
||||
Source string
|
||||
SourceSha256 []byte
|
||||
CustomTests []byte
|
||||
IdempotencyScope []byte
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) InsertAssessmentPracticeSubmission(ctx context.Context, arg InsertAssessmentPracticeSubmissionParams) error {
|
||||
_, err := q.db.Exec(ctx, insertAssessmentPracticeSubmission,
|
||||
arg.ID,
|
||||
arg.PracticeID,
|
||||
arg.UserID,
|
||||
arg.Mode,
|
||||
arg.Language,
|
||||
arg.Source,
|
||||
arg.SourceSha256,
|
||||
arg.CustomTests,
|
||||
arg.IdempotencyScope,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const lockAssessmentAttemptForPractice = `-- name: LockAssessmentAttemptForPractice :one
|
||||
|
||||
SELECT
|
||||
attempt.state,
|
||||
attempt.expires_at,
|
||||
clock_timestamp()::timestamptz AS database_time
|
||||
FROM assessment_attempts AS attempt
|
||||
WHERE
|
||||
attempt.id = $1
|
||||
AND attempt.user_id = $2
|
||||
FOR SHARE
|
||||
`
|
||||
|
||||
type LockAssessmentAttemptForPracticeParams struct {
|
||||
AttemptID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
}
|
||||
|
||||
type LockAssessmentAttemptForPracticeRow struct {
|
||||
State string
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
DatabaseTime pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Lock order of a practice command: the idempotency record, the attempt in
|
||||
// share mode, then the practice row. The attempt flows lock the attempt
|
||||
// first as well, so a practice command never waits for them in the opposite
|
||||
// order.
|
||||
// Locks the owner's attempt in share mode, so its state cannot change while
|
||||
// a practice command decides on it, and reads the database time after the
|
||||
// lock.
|
||||
func (q *Queries) LockAssessmentAttemptForPractice(ctx context.Context, arg LockAssessmentAttemptForPracticeParams) (LockAssessmentAttemptForPracticeRow, error) {
|
||||
row := q.db.QueryRow(ctx, lockAssessmentAttemptForPractice, arg.AttemptID, arg.UserID)
|
||||
var i LockAssessmentAttemptForPracticeRow
|
||||
err := row.Scan(&i.State, &i.ExpiresAt, &i.DatabaseTime)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const lockAssessmentPractice = `-- name: LockAssessmentPractice :one
|
||||
SELECT
|
||||
practice.id,
|
||||
practice.attempt_id,
|
||||
practice.user_id,
|
||||
practice.kind,
|
||||
practice.task,
|
||||
practice.status,
|
||||
practice.failure_reason,
|
||||
practice.submitted_at,
|
||||
practice.created_at
|
||||
FROM assessment_practices AS practice
|
||||
WHERE
|
||||
practice.id = $1
|
||||
AND practice.attempt_id = $2
|
||||
AND practice.user_id = $3
|
||||
FOR UPDATE
|
||||
`
|
||||
|
||||
type LockAssessmentPracticeParams struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
}
|
||||
|
||||
type LockAssessmentPracticeRow struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Kind string
|
||||
Task []byte
|
||||
Status string
|
||||
FailureReason pgtype.Text
|
||||
SubmittedAt pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
// Locks one practice of the owner's attempt for a state change.
|
||||
func (q *Queries) LockAssessmentPractice(ctx context.Context, arg LockAssessmentPracticeParams) (LockAssessmentPracticeRow, error) {
|
||||
row := q.db.QueryRow(ctx, lockAssessmentPractice, arg.ID, arg.AttemptID, arg.UserID)
|
||||
var i LockAssessmentPracticeRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.AttemptID,
|
||||
&i.UserID,
|
||||
&i.Kind,
|
||||
&i.Task,
|
||||
&i.Status,
|
||||
&i.FailureReason,
|
||||
&i.SubmittedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateAssessmentPracticeState = `-- name: UpdateAssessmentPracticeState :execrows
|
||||
UPDATE assessment_practices
|
||||
SET
|
||||
status = $1,
|
||||
failure_reason = $2,
|
||||
submitted_at = $3,
|
||||
updated_at = greatest(updated_at, $4::timestamptz)
|
||||
WHERE id = $5
|
||||
`
|
||||
|
||||
type UpdateAssessmentPracticeStateParams struct {
|
||||
Status string
|
||||
FailureReason pgtype.Text
|
||||
SubmittedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
ID pgtype.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAssessmentPracticeState(ctx context.Context, arg UpdateAssessmentPracticeStateParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateAssessmentPracticeState,
|
||||
arg.Status,
|
||||
arg.FailureReason,
|
||||
arg.SubmittedAt,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
@@ -229,6 +229,43 @@ type AssessmentLeakTrace struct {
|
||||
EvidenceBits int32
|
||||
}
|
||||
|
||||
type AssessmentPractice struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Kind string
|
||||
Task []byte
|
||||
Status string
|
||||
FailureReason pgtype.Text
|
||||
SubmittedAt pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type AssessmentPracticeJob struct {
|
||||
SubmissionID pgtype.UUID
|
||||
Mode string
|
||||
State string
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
FinishedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type AssessmentPracticeSubmission struct {
|
||||
ID pgtype.UUID
|
||||
PracticeID pgtype.UUID
|
||||
UserID pgtype.UUID
|
||||
Mode string
|
||||
Language string
|
||||
Source string
|
||||
SourceSha256 []byte
|
||||
CustomTests []byte
|
||||
IdempotencyScope []byte
|
||||
Result []byte
|
||||
ResultAt pgtype.Timestamptz
|
||||
CreatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type AssessmentReviewRead struct {
|
||||
ID pgtype.UUID
|
||||
AttemptID pgtype.UUID
|
||||
|
||||
@@ -277,6 +277,9 @@ type Querier interface {
|
||||
// NULL retry_at. due_at keeps the deadline. The same guard as the
|
||||
// completion applies.
|
||||
FailScheduledJob(ctx context.Context, arg FailScheduledJobParams) (int64, error)
|
||||
// Finds the latest submission of the owner under an idempotency scope, which
|
||||
// a replay returns.
|
||||
FindAssessmentPracticeSubmissionByScope(ctx context.Context, arg FindAssessmentPracticeSubmissionByScopeParams) (FindAssessmentPracticeSubmissionByScopeRow, error)
|
||||
// The unmarked statements of real attempts whose text, with runs of white space
|
||||
// collapsed, contains the fragment. The fragment is matched literally: position
|
||||
// is not a pattern. The scan reads the stored variant of every item, which is
|
||||
@@ -314,6 +317,8 @@ type Querier interface {
|
||||
GetAssessmentClientSignalTotals(ctx context.Context, attemptID pgtype.UUID) (GetAssessmentClientSignalTotalsRow, error)
|
||||
GetAssessmentFamilyByID(ctx context.Context, id pgtype.UUID) (AssessmentFamily, error)
|
||||
GetAssessmentFamilyVersion(ctx context.Context, arg GetAssessmentFamilyVersionParams) (AssessmentFamily, error)
|
||||
// Reads a debug run of the owner's attempt with the state of its job.
|
||||
GetAssessmentPracticeRun(ctx context.Context, arg GetAssessmentPracticeRunParams) (GetAssessmentPracticeRunRow, error)
|
||||
// The attempt a review job works on: real attempts only.
|
||||
GetAssessmentReviewSubject(ctx context.Context, attemptID pgtype.UUID) (pgtype.UUID, error)
|
||||
// Counts eligible root attempts in a policy window and computes the instant
|
||||
@@ -390,6 +395,9 @@ type Querier interface {
|
||||
// for the account's own view of its mail. It selects no address and no
|
||||
// content. The recipient index narrows the scan to the account's rows.
|
||||
GetLatestDeliveryStatus(ctx context.Context, arg GetLatestDeliveryStatusParams) (GetLatestDeliveryStatusRow, error)
|
||||
// The latest final submission of a practice: the solution the practice
|
||||
// state describes.
|
||||
GetLatestFinalPracticeSubmission(ctx context.Context, practiceID pgtype.UUID) (GetLatestFinalPracticeSubmissionRow, error)
|
||||
// The pending credentials of the newest token of a registration, for a
|
||||
// resend, which issues its token with the same credentials.
|
||||
GetLatestPendingRegistration(ctx context.Context, arg GetLatestPendingRegistrationParams) (GetLatestPendingRegistrationRow, error)
|
||||
@@ -487,6 +495,11 @@ type Querier interface {
|
||||
InsertAssessmentFamily(ctx context.Context, arg InsertAssessmentFamilyParams) (AssessmentFamily, error)
|
||||
InsertAssessmentLeakTrace(ctx context.Context, arg InsertAssessmentLeakTraceParams) error
|
||||
InsertAssessmentOriginMark(ctx context.Context, arg InsertAssessmentOriginMarkParams) error
|
||||
InsertAssessmentPractice(ctx context.Context, arg InsertAssessmentPracticeParams) error
|
||||
// Queues the execution job of a submission in the transaction that stores
|
||||
// the submission.
|
||||
InsertAssessmentPracticeJob(ctx context.Context, arg InsertAssessmentPracticeJobParams) error
|
||||
InsertAssessmentPracticeSubmission(ctx context.Context, arg InsertAssessmentPracticeSubmissionParams) error
|
||||
InsertAssessmentReviewRead(ctx context.Context, arg InsertAssessmentReviewReadParams) error
|
||||
// The attempt row is already locked by the caller. Store a parent before its
|
||||
// bounded child events, in the same transaction as the immutable receipt.
|
||||
@@ -829,6 +842,14 @@ type Querier interface {
|
||||
LockActiveMembership(ctx context.Context, arg LockActiveMembershipParams) (LockActiveMembershipRow, error)
|
||||
// Locks one owner-scoped attempt while a session command performs its CAS.
|
||||
LockAssessmentAttemptForCandidate(ctx context.Context, arg LockAssessmentAttemptForCandidateParams) (AssessmentAttempt, error)
|
||||
// Lock order of a practice command: the idempotency record, the attempt in
|
||||
// share mode, then the practice row. The attempt flows lock the attempt
|
||||
// first as well, so a practice command never waits for them in the opposite
|
||||
// order.
|
||||
// Locks the owner's attempt in share mode, so its state cannot change while
|
||||
// a practice command decides on it, and reads the database time after the
|
||||
// lock.
|
||||
LockAssessmentAttemptForPractice(ctx context.Context, arg LockAssessmentAttemptForPracticeParams) (LockAssessmentAttemptForPracticeRow, error)
|
||||
// Serializes root quota checks for one candidate before taking its optional
|
||||
// specialization or training lock. All callers acquire these locks in order.
|
||||
LockAssessmentAttemptScope(ctx context.Context, arg LockAssessmentAttemptScopeParams) error
|
||||
@@ -836,6 +857,8 @@ type Querier interface {
|
||||
// published or open the category, until the transaction ends. The key is
|
||||
// namespaced, so it cannot collide with another use of advisory locks.
|
||||
LockAssessmentCategory(ctx context.Context, category string) error
|
||||
// Locks one practice of the owner's attempt for a state change.
|
||||
LockAssessmentPractice(ctx context.Context, arg LockAssessmentPracticeParams) (LockAssessmentPracticeRow, error)
|
||||
// Serializes the evaluations of one review. A job takes these locks for every
|
||||
// attempt it will write, in ascending attempt order, before it reads any fact,
|
||||
// so what it reads is what the previous writer committed.
|
||||
@@ -1220,6 +1243,7 @@ type Querier interface {
|
||||
// Applies an answer, expiry, or finalization transition after the attempt row
|
||||
// is locked. Session limits and all immutable pins remain unchanged.
|
||||
UpdateAssessmentAttemptTransition(ctx context.Context, arg UpdateAssessmentAttemptTransitionParams) (AssessmentAttempt, error)
|
||||
UpdateAssessmentPracticeState(ctx context.Context, arg UpdateAssessmentPracticeStateParams) (int64, error)
|
||||
// Replaces the publication over the version the caller read and advances the
|
||||
// version in the same statement. No row returns for a stale version, which
|
||||
// the caller answers as a version conflict. The update time never moves back,
|
||||
|
||||
Reference in new issue
Block a user