provider

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package provider defines the provider-neutral durable job store contract. Implementations own their SQL, their DDL bootstrap, and database-time semantics; callers never receive executable SQL and never name a table.

Index

Constants

View Source
const (
	MaximumClaimJobs      = 256
	MaximumClaimTypes     = 256
	MaximumRetentionRows  = 4096
	MaximumPayloadBytes   = 1 << 20
	MaximumKeyBytes       = 256
	MaximumOperatorBatch  = 256
	MaximumIdentityBytes  = 64
	CodeAttemptsExhausted = "attempts_exhausted"
	CodeCanceled          = "canceled"
)

Variables

View Source
var ErrNotFound = errors.New("QUEUE_JOB_NOT_FOUND: job is absent")

ErrNotFound reports an inspection of an absent job.

Functions

func NewIdentifier

func NewIdentifier() (string, error)

NewIdentifier returns a canonical UUIDv4 without importing a general UUID package into provider implementations. It supplies both job identities and per-claim lease tokens.

func ValidateClaim

func ValidateClaim(options ClaimOptions) error

func ValidateClaimResource

func ValidateClaimResource(resource ClaimResource) error

ValidateClaimResource refuses ambiguous or unbounded shared-resource plans.

func ValidateCode

func ValidateCode(code string) error

func ValidateCountQuery

func ValidateCountQuery(query CountQuery) error

ValidateCountQuery refuses ambiguous operator counts.

func ValidateDelay

func ValidateDelay(delay time.Duration) error

func ValidateEnqueue

func ValidateEnqueue(request EnqueueRequest) error

func ValidateFailedQuery

func ValidateFailedQuery(query FailedQuery) error

ValidateFailedQuery refuses unbounded or unstable operator discovery.

func ValidateIdentity

func ValidateIdentity(id, token string) error

func ValidateJobIdentity

func ValidateJobIdentity(id string) error

func ValidateJobQuery

func ValidateJobQuery(query JobQuery) error

ValidateJobQuery refuses unbounded or unstable operator discovery.

func ValidateLease

func ValidateLease(duration time.Duration) error

func ValidateOperatorIDs

func ValidateOperatorIDs(ids []string) error

ValidateOperatorIDs refuses unbounded or ambiguous bulk recovery.

func ValidateRetention

func ValidateRetention(policy RetentionPolicy) error

Types

type CancelBatch

type CancelBatch struct {
	Changed  int
	Terminal []CancelResult
}

CancelBatch carries partial progress and the immediate terminal transitions an operator must observe.

type CancelResult

type CancelResult struct {
	Changed      bool
	Terminal     bool
	Type         string
	AttemptCount int64
}

CancelResult distinguishes immediate terminal cancellation from a durable request observed later by the lease owner.

type ClaimOptions

type ClaimOptions struct {
	Types         []string
	Limit         int
	LeaseDuration time.Duration
	Resource      *ClaimResource
}

ClaimOptions bounds one claim. An empty Types list claims nothing, which is how a worker whose every registered type is saturated stands down.

type ClaimResource

type ClaimResource struct {
	Name        string
	Concurrency int64
	Costs       map[string]int64
}

ClaimResource is one normalized fleet-wide weighted concurrency budget.

type CountQuery

type CountQuery struct {
	Types []string
}

CountQuery selects the job types included in state counts.

type EnqueueRequest

type EnqueueRequest struct {
	ID           string
	Type         string
	Payload      []byte
	MaxAttempts  int
	Delay        time.Duration
	DedupeKey    string
	ExclusiveKey string
}

EnqueueRequest is one durable insert. ID is the caller's proposed identity; a dedupe collision with active work returns the existing identity instead.

type EnqueueResult

type EnqueueResult struct {
	ID       string
	State    State
	Inserted bool
}

EnqueueResult identifies the active job selected by an enqueue and whether this request inserted it. State is the active row state observed while the enqueue decision was serialized.

type Executor

type Executor interface {
	ExecContext(ctx context.Context, query string, arguments ...any) (sql.Result, error)
	QueryRowContext(ctx context.Context, query string, arguments ...any) *sql.Row
}

Executor is the seam a transactional enqueue runs on. Both *sqlx.DB and *sqlx.Tx satisfy it, so an enqueue can join the caller's transaction rather than escaping to the pool.

type FailedCursor

type FailedCursor struct {
	FinishedAt time.Time
	ID         string
}

FailedCursor is the stable position immediately after one failed job.

type FailedPage

type FailedPage struct {
	Jobs []Summary
	More bool
}

FailedPage carries payload-free failed jobs and whether another page exists.

type FailedQuery

type FailedQuery struct {
	Types  []string
	Limit  int
	Before *FailedCursor
}

FailedQuery selects one bounded page of failed jobs.

type JobCursor

type JobCursor struct {
	EnqueuedAt time.Time
	ID         string
}

JobCursor is the stable position immediately after one listed job.

type JobPage

type JobPage struct {
	Jobs []Summary
	More bool
}

JobPage carries payload-free jobs and whether another page exists.

type JobQuery

type JobQuery struct {
	Types  []string
	States []State
	Limit  int
	Before *JobCursor
}

JobQuery selects one bounded payload-free page of jobs.

type Record

type Record struct {
	ID              string
	Type            string
	Payload         []byte
	State           State
	AttemptCount    int64
	MaxAttempts     int64
	AvailableAt     time.Time
	LeaseToken      string
	LeaseUntil      *time.Time
	DedupeKey       string
	ExclusiveKey    string
	CancelRequested bool
	LastCode        string
	EnqueuedAt      time.Time
	FinishedAt      *time.Time
	UpdatedAt       time.Time
}

Record is one sanitized durable job row. It carries the payload bytes a worker must decode and no SQL, driver text, or lease bookkeeping beyond the token that fences this owner's transitions.

func CloneRecords

func CloneRecords(records []Record) []Record

CloneRecords copies every record's payload so a claimed batch cannot alias provider buffers.

type Renewal

type Renewal struct {
	Renewed         bool
	CancelRequested bool
}

Renewal is the result of one fenced heartbeat. CancelRequested carries the durable cancellation flag, so renewal doubles as the cancellation poll.

type RetentionPolicy

type RetentionPolicy struct {
	OlderThan time.Time
	MaxRows   int
	States    []State
}

RetentionPolicy bounds one retention run over terminal rows.

type State

type State string

State is the durable job state. It mirrors queue.State without importing the public package into provider implementations.

const (
	StatePending   State = "pending"
	StateLeased    State = "leased"
	StateSucceeded State = "succeeded"
	StateFailed    State = "failed"
	StateCanceled  State = "canceled"
)

func RetentionStates

func RetentionStates(policy RetentionPolicy) []State

RetentionStates returns the selected terminal states or every terminal state.

type StateCounts

type StateCounts struct {
	Pending   int64
	Leased    int64
	Succeeded int64
	Failed    int64
	Canceled  int64
}

StateCounts is the number of stored jobs in each durable state.

type Store

type Store interface {
	EnsureSchema(ctx context.Context) error
	Enqueue(ctx context.Context, executor Executor, request EnqueueRequest) (EnqueueResult, error)
	Claim(ctx context.Context, options ClaimOptions) ([]Record, error)
	Renew(ctx context.Context, id, token string, duration time.Duration) (Renewal, error)
	Succeed(ctx context.Context, id, token, code string) (bool, error)
	Fail(ctx context.Context, id, token, code string) (bool, error)
	RetryAt(ctx context.Context, id, token string, delay time.Duration, code string, uncounted bool) (bool, error)
	MarkCanceled(ctx context.Context, id, token, code string) (bool, error)
	Release(ctx context.Context, id, token string) (bool, error)
	Inspect(ctx context.Context, id string) (Record, error)
	List(ctx context.Context, query JobQuery) (JobPage, error)
	ListFailed(ctx context.Context, query FailedQuery) (FailedPage, error)
	CountByState(ctx context.Context, query CountQuery) (StateCounts, error)
	Cancel(ctx context.Context, id string) (CancelResult, error)
	CancelMany(ctx context.Context, ids []string) (CancelBatch, error)
	Requeue(ctx context.Context, id string) (bool, error)
	RequeueFailed(ctx context.Context, ids []string) (int, error)
	RunRetention(ctx context.Context, policy RetentionPolicy) (int, error)
}

Store is the sole mutable seam for _golem_queue. Every token-fenced transition reports changed=false for a stale lease rather than allowing it to mutate a row another worker now owns.

type Summary

type Summary struct {
	ID              string
	Type            string
	State           State
	AttemptCount    int64
	MaxAttempts     int64
	AvailableAt     time.Time
	CancelRequested bool
	LastCode        string
	EnqueuedAt      time.Time
	FinishedAt      *time.Time
}

Summary is the payload-free projection used by queue operators.

Directories

Path Synopsis
Package providertest contains the provider-neutral durable job store conformance gates.
Package providertest contains the provider-neutral durable job store conformance gates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL