Versions in this module Expand all Collapse all v0 v0.1.1 Oct 25, 2026 v0.1.0 Oct 21, 2026 Changes in this version + const DefaultCancelledJobRetention + const DefaultCleanerInterval + const DefaultCompletedJobRetention + const DefaultDiscardedJobRetention + const DefaultFetchInterval + const DefaultHeartbeatInterval + const DefaultListLimit + const DefaultMaxArgsBytes + const DefaultMaxAttempts + const DefaultMaxWorkers + const DefaultPriority + const DefaultQueue + const DefaultReindexInterval + const DefaultRescueStuckJobsAfter + const DefaultSchema + const MaxListLimit + var ErrAlreadyStarted = errors.New("foreman: client already started") + var ErrArgsTooLarge = errors.New("foreman: args too large") + var ErrClientStopping = job.ErrClientStopping + var ErrInvalidArgument = errors.New("foreman: invalid argument") + var ErrInvalidConfig = errors.New("foreman: invalid config") + var ErrInvalidInsertOpts = errors.New("foreman: invalid insert options") + var ErrInvalidTransition = job.ErrInvalidTransition + var ErrNoWorker = job.ErrNoWorker + var ErrNotFound = job.ErrNotFound + var ErrNotInWorker = errors.New("foreman: not called from inside Work") + var ErrNotStarted = errors.New("foreman: client not started") + var ErrSchemaNotMigrated = errors.New("foreman: schema not migrated") + var ErrStaleJob = job.ErrStale + var ErrUniqueArgsNotCanonical = unique.ErrArgsNotCanonical + var ErrUniqueConflict = job.ErrUniqueConflict + func AddWorker[T JobArgs](w *Workers, worker Worker[T], opts ...WorkerOption) + func Cancel(err error) error + func CompleteTx[T JobArgs](ctx context.Context, tx pgx.Tx, job *Job[T]) error + func DecodeArgs[T JobArgs](row *JobRow) (T, error) + func Discard(err error) error + func Heartbeat(ctx context.Context) + func Snooze(d time.Duration) error + type AttemptError struct + At time.Time + Attempt int + Error string + Trace string + type Client struct + func ClientFromContext(ctx context.Context) *Client + func NewClient(pool *pgxpool.Pool, cfg Config) (*Client, error) + func (c *Client) ID() string + func (c *Client) Insert(ctx context.Context, args JobArgs, opts *InsertOpts) (*InsertResult, error) + func (c *Client) InsertMany(ctx context.Context, params []InsertParams) ([]*InsertResult, error) + func (c *Client) InsertManyTx(ctx context.Context, tx pgx.Tx, params []InsertParams) ([]*InsertResult, error) + func (c *Client) InsertTx(ctx context.Context, tx pgx.Tx, args JobArgs, opts *InsertOpts) (*InsertResult, error) + func (c *Client) IsLeader() bool + func (c *Client) JobCancel(ctx context.Context, id int64) (*JobRow, error) + func (c *Client) JobDeleteMany(ctx context.Context, f *JobFilter) (int, error) + func (c *Client) JobDiscard(ctx context.Context, id int64) (*JobRow, error) + func (c *Client) JobDiscardMany(ctx context.Context, f *JobFilter) (int, error) + func (c *Client) JobGet(ctx context.Context, id int64) (*JobRow, error) + func (c *Client) JobList(ctx context.Context, p *JobListParams) (*JobListResult, error) + func (c *Client) JobRetry(ctx context.Context, id int64) (*JobRow, error) + func (c *Client) JobRetryMany(ctx context.Context, f *JobFilter) (int, error) + func (c *Client) JobWork(ctx context.Context, id int64) (*JobRow, error) + func (c *Client) LeaderGet(ctx context.Context) (*LeaderInfo, error) + func (c *Client) PeriodicList(ctx context.Context) ([]*PeriodicInfo, error) + func (c *Client) Pool() *pgxpool.Pool + func (c *Client) QueueList(ctx context.Context) ([]*QueueInfo, error) + func (c *Client) QueuePause(ctx context.Context, name string) error + func (c *Client) QueueResume(ctx context.Context, name string) error + func (c *Client) Schema() string + func (c *Client) Start(ctx context.Context) error + func (c *Client) Stop(ctx context.Context) error + func (c *Client) StopAndCancel(ctx context.Context) error + type Clock = clock.Clock + type Config struct + CancelledJobRetention time.Duration + CleanerInterval time.Duration + Clock Clock + CompletedJobRetention time.Duration + DiscardedJobRetention time.Duration + ErrorHandler ErrorHandler + HeartbeatInterval time.Duration + ID string + JobTimeout time.Duration + Logger *slog.Logger + MaxArgsBytes int + Middleware []Middleware + PeriodicJobs []*PeriodicJob + PollOnly bool + Queues map[string]QueueConfig + Registerer prometheus.Registerer + ReindexInterval time.Duration + RescueStuckJobsAfter time.Duration + RetryPolicy RetryPolicy + Schema string + TracerProvider trace.TracerProvider + Workers *Workers + type ConstantBackoff struct + Delay time.Duration + func (c ConstantBackoff) NextRetry(_ JobRow, now time.Time) time.Time + type ErrorHandler interface + HandleError func(ctx context.Context, job *JobRow, err error) *ErrorHandlerResult + HandlePanic func(ctx context.Context, job *JobRow, panicVal any, trace string) *ErrorHandlerResult + type ErrorHandlerResult struct + SetCancelled bool + SetDiscarded bool + SnoozeFor time.Duration + type ExponentialBackoff struct + Base time.Duration + Cap time.Duration + func (e ExponentialBackoff) NextRetry(job JobRow, now time.Time) time.Time + type InsertOpts struct + ConcurrencyKey string + MaxAttempts int + Metadata json.RawMessage + Priority int + Queue string + ScheduledAt time.Time + Tags []string + Timeout time.Duration + UniqueOpts *UniqueOpts + type InsertParams struct + Args JobArgs + InsertOpts *InsertOpts + type InsertResult struct + Job *JobRow + UniqueSkippedAsDuplicate bool + type Job struct + Args T + Attempt int + CreatedAt time.Time + Errors []AttemptError + ID int64 + MaxAttempts int + Metadata json.RawMessage + Priority int + Queue string + ScheduledAt time.Time + Tags []string + type JobArgs interface + Kind func() string + type JobArgsWithInsertOpts interface + InsertOpts func() InsertOpts + type JobFilter struct + CreatedAfter time.Time + CreatedBefore time.Time + Kinds []string + Queues []string + States []State + type JobListParams struct + Cursor string + Kinds []string + Limit int + Queues []string + States []State + type JobListResult struct + Jobs []*JobRow + NextCursor string + type JobRow struct + Args json.RawMessage + Attempt int + AttemptedAt *time.Time + AttemptedBy []string + CancelRequestedAt *time.Time + ConcurrencyKey string + CreatedAt time.Time + Errors []AttemptError + FinalizedAt *time.Time + HeartbeatAt *time.Time + ID int64 + Kind string + MaxAttempts int + Metadata json.RawMessage + Priority int + Queue string + ScheduledAt time.Time + State State + Tags []string + Timeout time.Duration + UniqueKey []byte + UniqueStates []State + type LeaderInfo struct + ElectedAt time.Time + ExpiresAt time.Time + LeaderID string + type Middleware interface + InsertMany func(ctx context.Context, params []InsertParams, ...) ([]*InsertResult, error) + Work func(ctx context.Context, job *JobRow, next func(ctx context.Context) error) error + type MiddlewareDefaults struct + func (MiddlewareDefaults) InsertMany(ctx context.Context, _ []InsertParams, ...) ([]*InsertResult, error) + func (MiddlewareDefaults) Work(ctx context.Context, _ *JobRow, next func(ctx context.Context) error) error + type PeriodicInfo struct + LastTick time.Time + Name string + Ticks int64 + type PeriodicJob struct + Args func() (JobArgs, *InsertOpts) + CatchUp time.Duration + Name string + RunOnStart bool + Schedule Schedule + TimeZone *time.Location + type QueueConfig struct + Fairness bool + FetchInterval time.Duration + MaxWorkers int + PerKeyLimit int + type QueueInfo struct + Available int64 + LastSeenAt *time.Time + Name string + Paused bool + PausedAt *time.Time + Retryable int64 + Running int64 + Scheduled int64 + type RetryPolicy interface + NextRetry func(job JobRow, now time.Time) time.Time + type RetryPolicyFunc func(job JobRow, now time.Time) time.Time + func (f RetryPolicyFunc) NextRetry(job JobRow, now time.Time) time.Time + type Schedule interface + Next func(t time.Time) time.Time + func Cron(expr string) (Schedule, error) + func Every(d time.Duration) Schedule + func MustCron(expr string) Schedule + type State string + const StateAvailable + const StateCancelled + const StateCompleted + const StateDiscarded + const StateRetryable + const StateRunning + const StateScheduled + type Ticker = clock.Ticker + type UniqueOpts struct + ByArgFields []string + ByArgs bool + ByPeriod time.Duration + ByQueue bool + ByState []State + type WorkFunc func(ctx context.Context, job *Job[T]) error + func (f WorkFunc[T]) Work(ctx context.Context, job *Job[T]) error + type Worker interface + Work func(ctx context.Context, job *Job[T]) error + type WorkerOption func(*workerEntry) + func WithMaxAttempts(n int) WorkerOption + func WithRetryPolicy(p RetryPolicy) WorkerOption + func WithTimeout(d time.Duration) WorkerOption + type Workers struct + func NewWorkers() *Workers + func (w *Workers) Kinds() []string