Documentation
¶
Overview ¶
Package sqlite provides a SQLite-backed implementation of store.Store.
Usage ¶
opts := sqlite.DefaultOptions()
s, err := sqlite.Open(ctx, "/path/to/sqi.db", opts)
if err != nil {
log.Fatal(err)
}
defer s.Close()
The returned *Store satisfies store.Store in full. It can be passed wherever a store.Store is expected, or used directly for the [Ping] method that is not part of the public interface (used by health checks).
Concurrency ¶
The store keeps two connection pools over the same database file.
Writes go through a pool opened with sql.DB.SetMaxOpenConns(1), which serializes every write through a single SQLite connection. That prevents write-write conflicts and avoids SQLITE_BUSY between concurrent goroutines.
Reads go through a second pool of up to [readPoolMaxConns] connections. WAL mode lets readers proceed concurrently with a writer, so a read need not queue behind one — and must not: a single large Store.CreateJobSubmission holds the write connection for as long as it takes to insert every task, which at job sizes this server accepts is measured in seconds. With one shared pool that stalls every other database user in the process, including the health checker, so an ordinary large render job reads as an outage.
The split is by statement, not by call site: anything whose SQL begins with SELECT is a read, everything else is a write. Several writes here are INSERT/UPDATE/DELETE ... RETURNING issued through QueryRow, so classifying by Go method would be wrong. Misclassifying a read as a write merely serializes it; misclassifying a write as a read puts it on a multi-connection pool, so anything ambiguous (a CTE, say) stays on the write pool.
Transactions always run on the write pool.
An in-memory or temporary database gets one pool for both roles: a second sql.Open on ":memory:" would open a different, empty database.
Migrations ¶
When Options.AutoMigrate is true (the default), Open calls goose.Up against the embedded migration FS before returning. Set AutoMigrate to false in HA deployments where migrations are applied explicitly with "sqi-server migrate up" before rolling out new server instances.
Index ¶
- type Options
- type Store
- func (s *Store) ActiveClaimCount(ctx context.Context, poolID string) (int, error)
- func (s *Store) AppendAuditEntry(ctx context.Context, entry store.AuditEntry) error
- func (s *Store) AssignTask(ctx context.Context, id, workerID string, assignedAt time.Time) error
- func (s *Store) Backup(ctx context.Context, destPath string) error
- func (s *Store) CancelJobAttempts(ctx context.Context, jobID string, endedAt time.Time) (int, error)
- func (s *Store) CancelJobStatus(ctx context.Context, id string) error
- func (s *Store) CancelJobTasks(ctx context.Context, jobID string, now time.Time, reason string) ([]store.Task, error)
- func (s *Store) Checkpoint(ctx context.Context) (walPages, checkpointed int, err error)
- func (s *Store) CheckpointTruncate(ctx context.Context) (walPages, checkpointed int, err error)
- func (s *Store) Close() error
- func (s *Store) CommittedCores(ctx context.Context, workerID string, fullMachineCost int) (int, error)
- func (s *Store) CountActiveTasksInFarm(ctx context.Context, farmID string) (int, error)
- func (s *Store) CountActiveTasksInQueue(ctx context.Context, queueID string) (int, error)
- func (s *Store) CountAdmins(ctx context.Context) (int, error)
- func (s *Store) CountIdleWorkers(ctx context.Context, farmID string) (int, error)
- func (s *Store) CountReadyTasksByQueue(ctx context.Context, farmID string, now time.Time) (map[string]int, error)
- func (s *Store) CountTasksByJob(ctx context.Context, jobID string) (map[store.TaskStatus]int, error)
- func (s *Store) CountUnschedulableTasksByJob(ctx context.Context, jobID string) (int, error)
- func (s *Store) CountUsers(ctx context.Context) (int, error)
- func (s *Store) CreateAPIKey(ctx context.Context, k store.APIKey) (store.APIKey, error)
- func (s *Store) CreateClaim(ctx context.Context, claim store.UsageClaim) (store.UsageClaim, error)
- func (s *Store) CreateComputeLocation(ctx context.Context, loc store.ComputeLocation) (store.ComputeLocation, error)
- func (s *Store) CreateFarm(ctx context.Context, farm store.Farm) (store.Farm, error)
- func (s *Store) CreateJob(ctx context.Context, job store.Job) (store.Job, error)
- func (s *Store) CreateJobDependencies(ctx context.Context, jobID string, upstreamIDs []string) error
- func (s *Store) CreateJobSubmission(ctx context.Context, sub store.JobSubmission) (store.JobSubmission, error)
- func (s *Store) CreateProduct(ctx context.Context, p store.Product) (store.Product, error)
- func (s *Store) CreateQueue(ctx context.Context, queue store.Queue) (store.Queue, error)
- func (s *Store) CreateSession(ctx context.Context, sess store.Session) (store.Session, error)
- func (s *Store) CreateStep(ctx context.Context, step store.Step) (store.Step, error)
- func (s *Store) CreateStorageLocation(ctx context.Context, loc store.StorageLocation) (store.StorageLocation, error)
- func (s *Store) CreateTask(ctx context.Context, task store.Task) (store.Task, error)
- func (s *Store) CreateTaskAttempt(ctx context.Context, attempt store.TaskAttempt) (store.TaskAttempt, error)
- func (s *Store) CreateTaskLog(ctx context.Context, log store.TaskLog) (store.TaskLog, error)
- func (s *Store) CreateUsagePool(ctx context.Context, pool store.UsagePool) (store.UsagePool, error)
- func (s *Store) CreateUser(ctx context.Context, u store.User) (store.User, error)
- func (s *Store) DeleteComputeLocation(ctx context.Context, id string) error
- func (s *Store) DeleteExpiredSessions(ctx context.Context, now time.Time) (int, error)
- func (s *Store) DeleteFarm(ctx context.Context, id string) error
- func (s *Store) DeleteJob(ctx context.Context, id string) error
- func (s *Store) DeleteOfflineWorkersBefore(ctx context.Context, cutoff time.Time) ([]store.Worker, error)
- func (s *Store) DeleteProduct(ctx context.Context, name string) error
- func (s *Store) DeleteQueue(ctx context.Context, id string) error
- func (s *Store) DeleteSession(ctx context.Context, id string) error
- func (s *Store) DeleteSessionsForUser(ctx context.Context, userID string) error
- func (s *Store) DeleteStorageLocation(ctx context.Context, id string) error
- func (s *Store) DeleteTerminalJobsBefore(ctx context.Context, cutoff time.Time, includeFailed bool) ([]store.DeletedJob, error)
- func (s *Store) DeleteUsagePool(ctx context.Context, id string) error
- func (s *Store) DeleteUser(ctx context.Context, id string) error
- func (s *Store) DeleteWorker(ctx context.Context, id string) error
- func (s *Store) DemoteStalledJobs(ctx context.Context, now time.Time) ([]string, error)
- func (s *Store) FailureReasonSummary(ctx context.Context, jobID string) (store.FailureSummary, error)
- func (s *Store) GetAPIKeyByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.APIKey, error)
- func (s *Store) GetAPIKeyUserByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.APIKey, store.User, error)
- func (s *Store) GetComputeLocation(ctx context.Context, id string) (store.ComputeLocation, error)
- func (s *Store) GetComputeLocationByName(ctx context.Context, name string) (store.ComputeLocation, error)
- func (s *Store) GetFarm(ctx context.Context, id string) (store.Farm, error)
- func (s *Store) GetJob(ctx context.Context, id string) (store.Job, error)
- func (s *Store) GetProductByName(ctx context.Context, name string) (store.Product, error)
- func (s *Store) GetQueue(ctx context.Context, id string) (store.Queue, error)
- func (s *Store) GetSessionByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.Session, error)
- func (s *Store) GetSessionUserByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.User, error)
- func (s *Store) GetStep(ctx context.Context, id string) (store.Step, error)
- func (s *Store) GetStorageLocation(ctx context.Context, id string) (store.StorageLocation, error)
- func (s *Store) GetStorageLocationByName(ctx context.Context, name string) (store.StorageLocation, error)
- func (s *Store) GetTask(ctx context.Context, id string) (store.Task, error)
- func (s *Store) GetTaskAttempt(ctx context.Context, id string) (store.TaskAttempt, error)
- func (s *Store) GetUsagePool(ctx context.Context, id string) (store.UsagePool, error)
- func (s *Store) GetUser(ctx context.Context, id string) (store.User, error)
- func (s *Store) GetUserByExternalID(ctx context.Context, authSource, externalID string) (store.User, error)
- func (s *Store) GetUserByUsername(ctx context.Context, username string) (store.User, error)
- func (s *Store) GetWorker(ctx context.Context, id string) (store.Worker, error)
- func (s *Store) LatestTaskAttempt(ctx context.Context, taskID string) (store.TaskAttempt, error)
- func (s *Store) LeaseReadyTask(ctx context.Context, taskID, workerID string, now time.Time) (bool, error)
- func (s *Store) ListAPIKeysForUser(ctx context.Context, userID string) ([]store.APIKey, error)
- func (s *Store) ListAuditEntries(ctx context.Context, entityType, entityID string) ([]store.AuditEntry, error)
- func (s *Store) ListBlockedJobs(ctx context.Context) ([]store.Job, error)
- func (s *Store) ListComputeLocations(ctx context.Context) ([]store.ComputeLocation, error)
- func (s *Store) ListDependents(ctx context.Context, upstreamJobID string) ([]string, error)
- func (s *Store) ListFarms(ctx context.Context) ([]store.Farm, error)
- func (s *Store) ListJobDependencyIDs(ctx context.Context, jobID string) ([]string, error)
- func (s *Store) ListJobs(ctx context.Context, opts store.ListJobsOptions) (store.Page[store.Job], error)
- func (s *Store) ListProducts(ctx context.Context) ([]store.Product, error)
- func (s *Store) ListQueues(ctx context.Context, opts store.ListQueuesOptions) (store.Page[store.Queue], error)
- func (s *Store) ListReadyTasks(ctx context.Context, farmID string, now time.Time, limit int) ([]store.Task, error)
- func (s *Store) ListStaleWorkers(ctx context.Context, before time.Time) ([]store.Worker, error)
- func (s *Store) ListSteps(ctx context.Context, jobID string) ([]store.Step, error)
- func (s *Store) ListStorageLocations(ctx context.Context) ([]store.StorageLocation, error)
- func (s *Store) ListTaskAttempts(ctx context.Context, taskID string) ([]store.TaskAttempt, error)
- func (s *Store) ListTaskLogs(ctx context.Context, attemptID string, afterNATSSeq int64, limit int) ([]store.TaskLog, error)
- func (s *Store) ListTasks(ctx context.Context, opts store.ListTasksOptions) (store.Page[store.Task], error)
- func (s *Store) ListUsagePoolUtilization(ctx context.Context) ([]store.UsagePoolUtilization, error)
- func (s *Store) ListUsagePools(ctx context.Context) ([]store.UsagePool, error)
- func (s *Store) ListUsers(ctx context.Context) ([]store.User, error)
- func (s *Store) ListWorkers(ctx context.Context, opts store.ListWorkersOptions) (store.Page[store.Worker], error)
- func (s *Store) ParkJob(ctx context.Context, jobID, reason string, now time.Time) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) ReclaimStaleAssignedTasks(ctx context.Context, cutoff time.Time) ([]store.Task, error)
- func (s *Store) ReclaimWorkerTasks(ctx context.Context, workerID string) (int, error)
- func (s *Store) RecordTaskFailure(ctx context.Context, attemptID, taskID string, exitCode *int, ...) (taskFailed, jobFailed int, firstClose bool, err error)
- func (s *Store) RegisterWorker(ctx context.Context, worker store.Worker) (store.Worker, error)
- func (s *Store) ReleaseAttemptClaims(ctx context.Context, taskAttemptID string, releasedAt time.Time) (int, error)
- func (s *Store) ReleaseClaim(ctx context.Context, id string, releasedAt time.Time) error
- func (s *Store) ReleaseJobClaims(ctx context.Context, jobID string, releasedAt time.Time) (int, error)
- func (s *Store) RequeueTaskForRetry(ctx context.Context, taskID string, retryAfter, now time.Time) (bool, error)
- func (s *Store) ResumeJob(ctx context.Context, jobID string, now time.Time) error
- func (s *Store) RetryTasks(ctx context.Context, jobID string, taskIDs []string, now time.Time) ([]store.Task, error)
- func (s *Store) RevokeAPIKey(ctx context.Context, id, userID string, now time.Time) error
- func (s *Store) SetTaskFailureReason(ctx context.Context, id, reason string) error
- func (s *Store) SetTaskFailureReasonIfEmpty(ctx context.Context, id, reason string) error
- func (s *Store) SetTaskUnschedulableReason(ctx context.Context, id, reason string) error
- func (s *Store) SetUserDisplayName(ctx context.Context, id, displayName string) (store.User, error)
- func (s *Store) SetUserPassword(ctx context.Context, id, passwordHash string) error
- func (s *Store) SetUserPasswordAndEvictSessions(ctx context.Context, id, passwordHash string) error
- func (s *Store) StartCheckpointer(ctx context.Context, interval time.Duration, logger *slog.Logger)
- func (s *Store) TerminateWorkerAttempts(ctx context.Context, workerID string, status store.AttemptStatus, ...) (int, error)
- func (s *Store) TouchAPIKeyLastUsed(ctx context.Context, id string, now time.Time) error
- func (s *Store) TransitionStepPendingTasks(ctx context.Context, stepID string, to store.TaskStatus, failureReason string) ([]store.Task, error)
- func (s *Store) TryClaimSlots(ctx context.Context, taskAttemptID string, claims []store.UsagePoolClaim, ...) error
- func (s *Store) UpdateComputeLocation(ctx context.Context, loc store.ComputeLocation) (store.ComputeLocation, error)
- func (s *Store) UpdateFarm(ctx context.Context, farm store.Farm) (store.Farm, error)
- func (s *Store) UpdateJob(ctx context.Context, job store.Job) (store.Job, error)
- func (s *Store) UpdateJobStatus(ctx context.Context, id string, status store.JobStatus) error
- func (s *Store) UpdateProduct(ctx context.Context, p store.Product) (store.Product, error)
- func (s *Store) UpdateQueue(ctx context.Context, queue store.Queue) (store.Queue, error)
- func (s *Store) UpdateStepStatus(ctx context.Context, id string, status store.StepStatus) error
- func (s *Store) UpdateStorageLocation(ctx context.Context, loc store.StorageLocation) (store.StorageLocation, error)
- func (s *Store) UpdateTaskAttempt(ctx context.Context, attempt store.TaskAttempt) (store.TaskAttempt, error)
- func (s *Store) UpdateTaskStatus(ctx context.Context, id string, status store.TaskStatus) error
- func (s *Store) UpdateUsagePool(ctx context.Context, pool store.UsagePool) (store.UsagePool, error)
- func (s *Store) UpdateUser(ctx context.Context, u store.User) (store.User, error)
- func (s *Store) UpdateWorker(ctx context.Context, worker store.Worker) (store.Worker, error)
- func (s *Store) UpdateWorkerHeartbeat(ctx context.Context, id string, at time.Time) error
- func (s *Store) UpdateWorkerStatus(ctx context.Context, id string, status store.WorkerStatus) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// AutoMigrate controls whether Open runs goose.Up to apply any pending
// migrations before returning. Default: true.
//
// Set to false in HA deployments where migrations are applied explicitly
// via "sqi-server migrate up" before starting new server instances.
AutoMigrate bool
}
Options configures Open.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns an Options with recommended defaults.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a SQLite-backed implementation of store.Store. Create one with Open; close it with [Close] when done.
func Open ¶
Open opens (or creates) the SQLite database at path, applies connection pragmas, optionally runs pending migrations, prepares all statements, and returns a ready-to-use *Store.
Open returns an error and releases all resources if any step fails.
func (*Store) ActiveClaimCount ¶
ActiveClaimCount implements store.UsageClaimStore.
func (*Store) AppendAuditEntry ¶
AppendAuditEntry implements store.AuditStore.
func (*Store) AssignTask ¶
AssignTask implements store.TaskStore.
func (*Store) Backup ¶
Backup creates a consistent, online copy of the database at destPath using SQLite's VACUUM INTO statement. The source database remains fully available for reads and writes during the operation.
VACUUM INTO is the SQL-level equivalent of the SQLite C online backup API (sqlite3_backup_*): it produces a clean, fully checkpointed snapshot of the live database in a single atomic operation. The modernc.org/sqlite driver does not expose the C backup API directly, so VACUUM INTO is the idiomatic replacement.
destPath must not already exist; SQLite will return an error if it does.
func (*Store) CancelJobAttempts ¶
func (s *Store) CancelJobAttempts(ctx context.Context, jobID string, endedAt time.Time) (int, error)
CancelJobAttempts implements store.TaskAttemptStore.
func (*Store) CancelJobStatus ¶
CancelJobStatus implements store.JobStore.
It issues a conditional UPDATE that only fires when the job is not already in a terminal state. When zero rows are affected the job is either missing or already terminal; a follow-up GetJob disambiguates:
- not found → store.ErrNotFound
- already canceled → nil (idempotent)
- completed or failed → store.ErrConflict
func (*Store) CancelJobTasks ¶
func (s *Store) CancelJobTasks(ctx context.Context, jobID string, now time.Time, reason string) ([]store.Task, error)
CancelJobTasks implements store.TaskStore.
The SELECT and UPDATE execute inside a single SQLite transaction so no concurrent scheduler tick can assign a task between observation and cancellation. The rows cursor is closed inside a helper closure before the UPDATE runs, which avoids any potential cursor/write contention on the single-connection pool.
func (*Store) Checkpoint ¶
Checkpoint runs a WAL checkpoint in PASSIVE mode, copying whatever committed WAL frames it can back into the main database file without ever waiting. It returns the number of WAL log pages and the number successfully checkpointed, and is the mode the periodic checkpointer uses.
IT MUST NOT BE TRUNCATE, and that is not a style preference. Reads run on their own connection pool (see the Concurrency section of the package doc), so a reader holding a WAL snapshot now blocks a truncating checkpoint — which invokes SQLite's busy handler and waits out the ENTIRE busy_timeout (5s) on the write connection before giving up, and still fails to truncate. Measured under four concurrent readers: busy=1, 119,888 of 134,522 frames, 5.019s. That would stall job submission, lease grants and every task-status write for five seconds on a five-minute timer — the same write stall the separate read pool exists to remove, reintroduced through the back door.
PASSIVE never invokes the busy handler: it transfers what it can and returns. A reader simply means fewer frames move this tick and the next one takes them. Pinned by TestCheckpoint_DoesNotBlockOnAReader.
The checkpoint runs on the write pool, which is still a single connection, so two checkpoints can never overlap.
func (*Store) CheckpointTruncate ¶ added in v0.3.0
CheckpointTruncate runs a WAL checkpoint in TRUNCATE mode, which additionally truncates the WAL to zero bytes once every frame is transferred.
It is for SHUTDOWN, where a WAL left at zero is worth waiting for and there is no next tick to finish the job. It can block for up to busy_timeout if a reader still holds a snapshot, which is acceptable once — and only once — on the way down. Do not call it on a timer; see Store.Checkpoint.
func (*Store) Close ¶
Close closes all prepared statements and both connection pools. It is safe to call Close more than once.
func (*Store) CommittedCores ¶
func (s *Store) CommittedCores(ctx context.Context, workerID string, fullMachineCost int) (int, error)
CommittedCores implements store.TaskStore.
func (*Store) CountActiveTasksInFarm ¶
CountActiveTasksInFarm implements store.TaskStore.
func (*Store) CountActiveTasksInQueue ¶
CountActiveTasksInQueue implements store.TaskStore.
func (*Store) CountAdmins ¶ added in v0.3.0
CountAdmins implements store.UserStore.
func (*Store) CountIdleWorkers ¶
CountIdleWorkers implements store.WorkerStore. When farmID is empty all farms are counted.
func (*Store) CountReadyTasksByQueue ¶
func (s *Store) CountReadyTasksByQueue(ctx context.Context, farmID string, now time.Time) (map[string]int, error)
CountReadyTasksByQueue implements store.TaskStore. Returns a map of queue ID → leasable ready-task count for the given farm. Queues with zero leasable tasks are omitted.
func (*Store) CountTasksByJob ¶
func (s *Store) CountTasksByJob(ctx context.Context, jobID string) (map[store.TaskStatus]int, error)
CountTasksByJob implements store.TaskStore. Returns the number of tasks for the given job keyed by status. Statuses with zero tasks are omitted from the returned map.
func (*Store) CountUnschedulableTasksByJob ¶ added in v0.2.0
CountUnschedulableTasksByJob implements store.TaskStore. Returns the number of ready tasks for the given job that carry a non-empty unschedulable reason.
func (*Store) CountUsers ¶ added in v0.3.0
CountUsers implements store.UserStore.
func (*Store) CreateAPIKey ¶ added in v0.3.0
CreateAPIKey implements store.APIKeyStore.
func (*Store) CreateClaim ¶
func (s *Store) CreateClaim(ctx context.Context, claim store.UsageClaim) (store.UsageClaim, error)
CreateClaim implements store.UsageClaimStore.
func (*Store) CreateComputeLocation ¶ added in v0.2.0
func (s *Store) CreateComputeLocation(ctx context.Context, loc store.ComputeLocation) (store.ComputeLocation, error)
CreateComputeLocation implements store.ComputeLocationStore.
func (*Store) CreateFarm ¶
CreateFarm implements store.FarmStore.
func (*Store) CreateJob ¶
CreateJob implements store.JobStore.
func (*Store) CreateJobDependencies ¶ added in v0.2.0
func (s *Store) CreateJobDependencies(ctx context.Context, jobID string, upstreamIDs []string) error
CreateJobDependencies implements store.JobStore. It records that jobID waits on each upstream ID; duplicate edges (job_id, depends_on_job_id) are silently ignored via INSERT OR IGNORE.
func (*Store) CreateJobSubmission ¶ added in v0.3.0
func (s *Store) CreateJobSubmission(ctx context.Context, sub store.JobSubmission) (store.JobSubmission, error)
CreateJobSubmission implements store.JobStore. Every row one submission creates — the job, its dependency edges, its steps and its tasks — is written in a single transaction, so a failure at any point leaves nothing behind.
Rows are inserted in foreign-key order (job, edges, steps, tasks) and each insert uses raw SQL via tx rather than the prepared statements the per-row creators use: a statement bound into a transaction with tx.StmtContext must itself be closed, and the other transactional writers here take the same approach (see UpdateTaskStatus in task.go).
Each step and task row is stamped with its OWN time.Now(), exactly as CreateStep and CreateTask do — see insertTasksTx for why sharing one timestamp across the batch would be a behavior change, not an optimization.
func (*Store) CreateProduct ¶ added in v0.2.0
CreateProduct implements store.ProductStore.
func (*Store) CreateQueue ¶
CreateQueue implements store.QueueStore.
func (*Store) CreateSession ¶ added in v0.3.0
CreateSession implements store.SessionStore.
Unlike CreateUser, this does not stamp CreatedAt (or ExpiresAt) server-side: both are caller-supplied by design, since ExpiresAt is derived from the issuance instant and the two timestamps must agree with each other.
func (*Store) CreateStep ¶
CreateStep implements store.StepStore.
func (*Store) CreateStorageLocation ¶
func (s *Store) CreateStorageLocation(ctx context.Context, loc store.StorageLocation) (store.StorageLocation, error)
CreateStorageLocation implements store.StorageLocationStore.
func (*Store) CreateTask ¶
CreateTask implements store.TaskStore.
func (*Store) CreateTaskAttempt ¶
func (s *Store) CreateTaskAttempt(ctx context.Context, attempt store.TaskAttempt) (store.TaskAttempt, error)
CreateTaskAttempt implements store.TaskAttemptStore.
func (*Store) CreateTaskLog ¶
CreateTaskLog implements store.TaskLogStore.
func (*Store) CreateUsagePool ¶
CreateUsagePool implements store.UsagePoolStore.
func (*Store) CreateUser ¶ added in v0.3.0
CreateUser implements store.UserStore.
func (*Store) DeleteComputeLocation ¶ added in v0.2.0
DeleteComputeLocation implements store.ComputeLocationStore.
func (*Store) DeleteExpiredSessions ¶ added in v0.3.0
DeleteExpiredSessions implements store.SessionStore.
func (*Store) DeleteFarm ¶
DeleteFarm implements store.FarmStore.
func (*Store) DeleteJob ¶
DeleteJob implements store.JobStore. The cascade runs in a single transaction; if the jobs-row delete affects zero rows the job did not exist and the transaction is rolled back with store.ErrNotFound.
func (*Store) DeleteOfflineWorkersBefore ¶
func (s *Store) DeleteOfflineWorkersBefore(ctx context.Context, cutoff time.Time) ([]store.Worker, error)
DeleteOfflineWorkersBefore implements store.WorkerStore.
func (*Store) DeleteProduct ¶ added in v0.2.0
DeleteProduct implements store.ProductStore.
func (*Store) DeleteQueue ¶
DeleteQueue implements store.QueueStore.
func (*Store) DeleteSession ¶ added in v0.3.0
DeleteSession implements store.SessionStore.
func (*Store) DeleteSessionsForUser ¶ added in v0.3.0
DeleteSessionsForUser implements store.SessionStore.
func (*Store) DeleteStorageLocation ¶
DeleteStorageLocation implements store.StorageLocationStore.
func (*Store) DeleteTerminalJobsBefore ¶
func (s *Store) DeleteTerminalJobsBefore( ctx context.Context, cutoff time.Time, includeFailed bool, ) ([]store.DeletedJob, error)
DeleteTerminalJobsBefore implements store.JobStore. It selects the eligible job IDs first, then deletes each via the shared cascade, all inside one transaction so a partially-applied sweep can never leave orphaned child rows.
func (*Store) DeleteUsagePool ¶
DeleteUsagePool implements store.UsagePoolStore.
func (*Store) DeleteUser ¶ added in v0.3.0
DeleteUser implements store.UserStore.
func (*Store) DeleteWorker ¶
DeleteWorker implements store.WorkerStore.
func (*Store) DemoteStalledJobs ¶
DemoteStalledJobs implements store.JobStore.
The single UPDATE ... RETURNING statement is atomic: a concurrent task transition to assigned/running cannot slip between the EXISTS check and the write, so a job that has just been re-activated is never spuriously demoted.
func (*Store) FailureReasonSummary ¶ added in v0.2.0
func (s *Store) FailureReasonSummary(ctx context.Context, jobID string) (store.FailureSummary, error)
FailureReasonSummary implements store.TaskStore.
func (*Store) GetAPIKeyByTokenHash ¶ added in v0.3.0
func (s *Store) GetAPIKeyByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.APIKey, error)
GetAPIKeyByTokenHash implements store.APIKeyStore.
func (*Store) GetAPIKeyUserByTokenHash ¶ added in v0.3.0
func (s *Store) GetAPIKeyUserByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.APIKey, store.User, error)
GetAPIKeyUserByTokenHash implements store.APIKeyStore.
func (*Store) GetComputeLocation ¶ added in v0.2.0
GetComputeLocation implements store.ComputeLocationStore.
func (*Store) GetComputeLocationByName ¶ added in v0.2.0
func (s *Store) GetComputeLocationByName(ctx context.Context, name string) (store.ComputeLocation, error)
GetComputeLocationByName implements store.ComputeLocationStore.
func (*Store) GetFarm ¶
GetFarm implements store.FarmStore.
func (*Store) GetJob ¶
GetJob implements store.JobStore.
func (*Store) GetProductByName ¶ added in v0.2.0
GetProductByName implements store.ProductStore.
func (*Store) GetQueue ¶
GetQueue implements store.QueueStore.
func (*Store) GetSessionByTokenHash ¶ added in v0.3.0
func (s *Store) GetSessionByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.Session, error)
GetSessionByTokenHash implements store.SessionStore.
func (*Store) GetSessionUserByTokenHash ¶ added in v0.3.0
func (s *Store) GetSessionUserByTokenHash(ctx context.Context, tokenHash string, now time.Time) (store.User, error)
GetSessionUserByTokenHash implements store.SessionStore.
func (*Store) GetStep ¶
GetStep implements store.StepStore.
func (*Store) GetStorageLocation ¶
GetStorageLocation implements store.StorageLocationStore.
func (*Store) GetStorageLocationByName ¶
func (s *Store) GetStorageLocationByName(ctx context.Context, name string) (store.StorageLocation, error)
GetStorageLocationByName implements store.StorageLocationStore.
func (*Store) GetTask ¶
GetTask implements store.TaskStore.
func (*Store) GetTaskAttempt ¶
GetTaskAttempt implements store.TaskAttemptStore.
func (*Store) GetUsagePool ¶
GetUsagePool implements store.UsagePoolStore.
func (*Store) GetUser ¶ added in v0.3.0
GetUser implements store.UserStore.
func (*Store) GetUserByExternalID ¶ added in v0.3.0
func (s *Store) GetUserByExternalID(ctx context.Context, authSource, externalID string) (store.User, error)
GetUserByExternalID implements store.UserStore.
func (*Store) GetUserByUsername ¶ added in v0.3.0
GetUserByUsername implements store.UserStore.
func (*Store) GetWorker ¶
GetWorker implements store.WorkerStore.
func (*Store) LatestTaskAttempt ¶
LatestTaskAttempt implements store.TaskAttemptStore.
func (*Store) LeaseReadyTask ¶
func (s *Store) LeaseReadyTask(ctx context.Context, taskID, workerID string, now time.Time) (bool, error)
LeaseReadyTask implements store.TaskStore.
func (*Store) ListAPIKeysForUser ¶ added in v0.3.0
ListAPIKeysForUser implements store.APIKeyStore.
func (*Store) ListAuditEntries ¶
func (s *Store) ListAuditEntries(ctx context.Context, entityType, entityID string) ([]store.AuditEntry, error)
ListAuditEntries implements store.AuditStore. Passing empty strings for both entityType and entityID returns all entries.
func (*Store) ListBlockedJobs ¶ added in v0.2.0
ListBlockedJobs implements store.JobStore. It returns every job currently in store.JobStatusBlocked.
func (*Store) ListComputeLocations ¶ added in v0.2.0
ListComputeLocations implements store.ComputeLocationStore.
func (*Store) ListDependents ¶ added in v0.2.0
ListDependents implements store.JobStore. It returns the IDs of jobs waiting on upstreamJobID, ordered by dependent job ID.
func (*Store) ListFarms ¶
ListFarms implements store.FarmStore.
func (*Store) ListJobDependencyIDs ¶ added in v0.2.0
ListJobDependencyIDs implements store.JobStore. It returns the upstream job IDs jobID waits on, ordered by upstream job ID.
func (*Store) ListJobs ¶
func (s *Store) ListJobs(ctx context.Context, opts store.ListJobsOptions) (store.Page[store.Job], error)
ListJobs implements store.JobStore. Dynamic filters use parameterised ad-hoc queries due to the variable WHERE clause. The sort column is looked up from a hard-coded allow-list before being interpolated into the SQL to prevent injection.
func (*Store) ListProducts ¶ added in v0.2.0
ListProducts implements store.ProductStore.
func (*Store) ListQueues ¶
func (s *Store) ListQueues(ctx context.Context, opts store.ListQueuesOptions) (store.Page[store.Queue], error)
ListQueues implements store.QueueStore. Dynamic filters use parameterised ad-hoc queries; the sort column is looked up from a hard-coded allow-list to prevent injection.
func (*Store) ListReadyTasks ¶
func (s *Store) ListReadyTasks(ctx context.Context, farmID string, now time.Time, limit int) ([]store.Task, error)
ListReadyTasks implements store.TaskStore.
func (*Store) ListStaleWorkers ¶
ListStaleWorkers implements store.WorkerStore.
func (*Store) ListSteps ¶
ListSteps implements store.StepStore.
func (*Store) ListStorageLocations ¶
ListStorageLocations implements store.StorageLocationStore.
func (*Store) ListTaskAttempts ¶
ListTaskAttempts implements store.TaskAttemptStore.
func (*Store) ListTaskLogs ¶
func (s *Store) ListTaskLogs(ctx context.Context, attemptID string, afterNATSSeq int64, limit int) ([]store.TaskLog, error)
ListTaskLogs implements store.TaskLogStore.
func (*Store) ListTasks ¶
func (s *Store) ListTasks(ctx context.Context, opts store.ListTasksOptions) (store.Page[store.Task], error)
ListTasks implements store.TaskStore. Dynamic filters use parameterised ad-hoc queries due to the variable WHERE clause. The sort column is looked up from a hard-coded allow-list.
func (*Store) ListUsagePoolUtilization ¶
ListUsagePoolUtilization implements store.UsagePoolStore.
func (*Store) ListUsagePools ¶
ListUsagePools implements store.UsagePoolStore.
func (*Store) ListUsers ¶ added in v0.3.0
ListUsers implements store.UserStore.
func (*Store) ListWorkers ¶
func (s *Store) ListWorkers(ctx context.Context, opts store.ListWorkersOptions) (store.Page[store.Worker], error)
ListWorkers implements store.WorkerStore. Dynamic filters are applied via parameterised ad-hoc queries because the WHERE clause varies; this is safe as all values are bound via placeholders. The sort column is looked up from a hard-coded allow-list.
func (*Store) ParkJob ¶ added in v0.2.0
ParkJob implements store.JobStore.
A zero-row UPDATE is ambiguous between "job not found" and "job already terminal"; a follow-up GetJob disambiguates the same way Store.CancelJobStatus does — terminal is a legitimate no-op (nil), missing propagates store.ErrNotFound.
func (*Store) Ping ¶
Ping verifies the database connection is still alive. Used by health checks.
It deliberately pings the READ pool, not the write pool. Readiness must report whether the database is reachable, and a large job submission holds the sole write connection for seconds at a time; pinging through it would turn a normal write into a failed health check. This is not an oversight — the health checker is not meant to observe write-pool queuing.
func (*Store) ReclaimStaleAssignedTasks ¶
func (s *Store) ReclaimStaleAssignedTasks(ctx context.Context, cutoff time.Time) ([]store.Task, error)
ReclaimStaleAssignedTasks implements store.TaskStore.
The SELECT and UPDATE run inside a single SQLite transaction so a concurrent "running" status update cannot slip a task out of 'assigned' between the observation and the reset; the UPDATE's status guard keeps the returned set and the reclaimed set identical. Mirrors Store.CancelJobTasks.
func (*Store) ReclaimWorkerTasks ¶
ReclaimWorkerTasks implements store.TaskStore.
func (*Store) RecordTaskFailure ¶ added in v0.2.0
func (s *Store) RecordTaskFailure( ctx context.Context, attemptID, taskID string, exitCode *int, sessionID, message string, now time.Time, ) (taskFailed, jobFailed int, firstClose bool, err error)
RecordTaskFailure implements store.TaskStore.
The attempt close, task increment, and job increment run inside a single transaction. The counter increments are GATED on the attempt's running→failed transition: closing the attempt (which only affects a row while it is still running) is what authorizes the increment, so an at-least-once redelivery of the same status message — whose attempt is already terminal — counts zero rows, skips both increments, and returns the current counts instead. This makes the failure count exactly-once per attempt, and keeps the two counters in lockstep: either both increment or neither does.
func (*Store) RegisterWorker ¶
RegisterWorker implements store.WorkerStore.
func (*Store) ReleaseAttemptClaims ¶
func (s *Store) ReleaseAttemptClaims(ctx context.Context, taskAttemptID string, releasedAt time.Time) (int, error)
ReleaseAttemptClaims implements store.UsageClaimStore.
func (*Store) ReleaseClaim ¶
ReleaseClaim implements store.UsageClaimStore.
func (*Store) ReleaseJobClaims ¶
func (s *Store) ReleaseJobClaims(ctx context.Context, jobID string, releasedAt time.Time) (int, error)
ReleaseJobClaims implements store.UsageClaimStore.
func (*Store) RequeueTaskForRetry ¶ added in v0.2.0
func (s *Store) RequeueTaskForRetry(ctx context.Context, taskID string, retryAfter, now time.Time) (bool, error)
RequeueTaskForRetry implements store.TaskStore. Zero rows (task missing or no longer assigned/running) is a legitimate no-op reported as false — NOT an error, so a stale redelivery never naks into a redelivery loop.
func (*Store) ResumeJob ¶ added in v0.2.0
ResumeJob implements store.JobStore.
A zero-row UPDATE is ambiguous between "job not found" and "job no longer paused"; a follow-up GetJob disambiguates the same way Store.ParkJob does — not-paused is a legitimate no-op (nil), missing propagates store.ErrNotFound.
func (*Store) RetryTasks ¶
func (s *Store) RetryTasks(ctx context.Context, jobID string, taskIDs []string, now time.Time) ([]store.Task, error)
RetryTasks implements store.TaskStore.
func (*Store) RevokeAPIKey ¶ added in v0.3.0
RevokeAPIKey implements store.APIKeyStore.
func (*Store) SetTaskFailureReason ¶ added in v0.2.0
SetTaskFailureReason implements store.TaskStore. An empty reason clears it.
func (*Store) SetTaskFailureReasonIfEmpty ¶ added in v0.2.0
SetTaskFailureReasonIfEmpty implements store.TaskStore. A zero-row update (task unknown or already carrying a reason) is a legitimate no-op, not an error.
func (*Store) SetTaskUnschedulableReason ¶ added in v0.2.0
SetTaskUnschedulableReason implements store.TaskStore.
func (*Store) SetUserDisplayName ¶ added in v0.3.0
SetUserDisplayName implements store.UserStore.
func (*Store) SetUserPassword ¶ added in v0.3.0
SetUserPassword implements store.UserStore.
func (*Store) SetUserPasswordAndEvictSessions ¶ added in v0.3.0
SetUserPasswordAndEvictSessions implements store.UserStore. Both writes share one transaction so a caller can report failure honestly.
func (*Store) StartCheckpointer ¶
StartCheckpointer launches a background goroutine that calls [Checkpoint] every interval. The goroutine exits when ctx is canceled, running one final checkpoint before returning so the WAL is fully flushed before the store is closed.
Errors are logged but do not stop the loop; transient checkpoint failures are not fatal. The caller does not need to wrap this in a goroutine — it manages its own.
func (*Store) TerminateWorkerAttempts ¶
func (s *Store) TerminateWorkerAttempts(ctx context.Context, workerID string, status store.AttemptStatus, endedAt time.Time) (int, error)
TerminateWorkerAttempts implements store.TaskAttemptStore.
func (*Store) TouchAPIKeyLastUsed ¶ added in v0.3.0
TouchAPIKeyLastUsed implements store.APIKeyStore.
func (*Store) TransitionStepPendingTasks ¶
func (s *Store) TransitionStepPendingTasks(ctx context.Context, stepID string, to store.TaskStatus, failureReason string) ([]store.Task, error)
TransitionStepPendingTasks implements store.TaskStore.
The UPDATE ... RETURNING runs as one statement so the transition is atomic and covers every pending task of the step regardless of count.
func (*Store) TryClaimSlots ¶
func (s *Store) TryClaimSlots( ctx context.Context, taskAttemptID string, claims []store.UsagePoolClaim, claimedAt time.Time, ) error
TryClaimSlots implements store.UsageClaimStore.
It opens a transaction, counts active claims for each pool in claims, and either inserts all claim rows (all pools have capacity) or rolls back and returns store.ErrUsageAtCapacity (at least one pool is saturated).
The transaction is serialized by the single-connection pool (SetMaxOpenConns(1)) so no other goroutine can modify claim counts between the count check and the inserts.
func (*Store) UpdateComputeLocation ¶ added in v0.2.0
func (s *Store) UpdateComputeLocation(ctx context.Context, loc store.ComputeLocation) (store.ComputeLocation, error)
UpdateComputeLocation implements store.ComputeLocationStore.
func (*Store) UpdateFarm ¶
UpdateFarm implements store.FarmStore.
func (*Store) UpdateJob ¶
UpdateJob implements store.JobStore. Only mutable user-settable fields are written (farm_id, queue_id, name, owner, submitter, priority, project, raw_template, template_format, max_attempts, retry_delay_seconds, failure_limit). status, started_at, completed_at, failed_attempts, and park_reason are never touched here; use UpdateJobStatus, CancelJobStatus, or the scheduler's failure-limit sweep for those.
func (*Store) UpdateJobStatus ¶
UpdateJobStatus implements store.JobStore.
func (*Store) UpdateProduct ¶ added in v0.2.0
UpdateProduct implements store.ProductStore.
func (*Store) UpdateQueue ¶
UpdateQueue implements store.QueueStore. See the type's doc comment for PreserveRunAsUser/PreserveRunAsGroup semantics.
Wrapped in an explicit transaction (rather than the single QueryRowContext every other Update* uses) because store.ErrRunAsGroupWithoutUser must be checked against the RESOLVED run_as_user/run_as_group — i.e. after the statement's own CASE WHEN preserve substitution — not the raw request fields: a PUT that omits run_as_user/run_as_group cannot tell from the request alone whether the preserved column will end up empty. RETURNING gives us those resolved values from the very statement that would commit them, so the invalid-combo check and the write see identical data with no separate read and therefore no read-then-write race. An invalid combo rolls the transaction back so the update has no effect at all, rather than committing a queue update while reporting an error.
func (*Store) UpdateStepStatus ¶
UpdateStepStatus implements store.StepStore.
func (*Store) UpdateStorageLocation ¶
func (s *Store) UpdateStorageLocation(ctx context.Context, loc store.StorageLocation) (store.StorageLocation, error)
UpdateStorageLocation implements store.StorageLocationStore.
func (*Store) UpdateTaskAttempt ¶
func (s *Store) UpdateTaskAttempt(ctx context.Context, attempt store.TaskAttempt) (store.TaskAttempt, error)
UpdateTaskAttempt implements store.TaskAttemptStore. If attempt.SessionID is non-empty it is written to the record; an empty value is treated as "no change" via COALESCE so callers that do not have a session ID (e.g. the cancellation path) do not overwrite an existing one.
func (*Store) UpdateTaskStatus ¶
UpdateTaskStatus implements store.TaskStore.
The write is gated by the task state machine (store.ValidateTaskTransition): a transition the machine does not permit is rejected with store.ErrInvalidTransition and leaves the row untouched.
Writing the status a task already holds is a no-op, not an error. Task status arrives over JetStream, which is at-least-once, so a redelivered message must not fail — the consumer would Nak it and redeliver forever.
The read and the write share a transaction, serialized by the single-connection pool (SetMaxOpenConns(1)), so no other goroutine can move the task between the check and the update. Mirrors Store.TryClaimSlots.
func (*Store) UpdateUsagePool ¶
UpdateUsagePool implements store.UsagePoolStore.
func (*Store) UpdateUser ¶ added in v0.3.0
UpdateUser implements store.UserStore.
func (*Store) UpdateWorker ¶
UpdateWorker implements store.WorkerStore.
func (*Store) UpdateWorkerHeartbeat ¶
UpdateWorkerHeartbeat implements store.WorkerStore.
func (*Store) UpdateWorkerStatus ¶
UpdateWorkerStatus implements store.WorkerStore.