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 underlying sql.DB is opened with sql.DB.SetMaxOpenConns(1) which serializes all reads and writes through a single SQLite connection. This is the correct setting for SQLite in WAL mode when used from a single process: it prevents write-write conflicts and avoids the overhead of connection negotiation while still allowing the WAL reader snapshot semantics to function correctly within a single connection.
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) 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) 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) 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) 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) 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) DeleteComputeLocation(ctx context.Context, id string) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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 TRUNCATE mode, which copies all committed WAL frames back into the main database file and then truncates the WAL to zero bytes. It returns the number of WAL log pages and the number successfully checkpointed.
TRUNCATE mode is appropriate for the periodic background case: because the store uses a single connection (SetMaxOpenConns(1)), there are no concurrent readers that could block the checkpoint, so all frames will always be transferred in one call.
func (*Store) Close ¶
Close closes all prepared statements and the underlying database connection. 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) 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) 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) CreateProduct ¶ added in v0.2.0
CreateProduct implements store.ProductStore.
func (*Store) CreateQueue ¶
CreateQueue implements store.QueueStore.
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) DeleteComputeLocation ¶ added in v0.2.0
DeleteComputeLocation implements store.ComputeLocationStore.
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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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.
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.
func (*Store) UpdateUsagePool ¶
UpdateUsagePool implements store.UsagePoolStore.
func (*Store) UpdateWorker ¶
UpdateWorker implements store.WorkerStore.
func (*Store) UpdateWorkerHeartbeat ¶
UpdateWorkerHeartbeat implements store.WorkerStore.
func (*Store) UpdateWorkerStatus ¶
UpdateWorkerStatus implements store.WorkerStore.