Documentation
¶
Overview ¶
Package liteq provides a PostgreSQL-backed task queue with retry and dead-letter support.
Index ¶
- Constants
- Variables
- func ParseRetryStrategy(s string) (string, error)
- type BaseHooks
- func (BaseHooks) OnDLQ(context.Context, string, string)
- func (BaseHooks) OnDLQFailed(context.Context, string, error)
- func (BaseHooks) OnDequeue(context.Context, string, int)
- func (BaseHooks) OnEnqueue(context.Context, string, string)
- func (BaseHooks) OnQueueDrained(context.Context, string)
- func (BaseHooks) OnQueuePaused(context.Context, string)
- func (BaseHooks) OnQueueResumed(context.Context, string)
- func (BaseHooks) OnRetry(context.Context, string, int, time.Time)
- func (BaseHooks) OnTaskComplete(context.Context, string, time.Duration)
- func (BaseHooks) OnTaskStart(context.Context, string)
- type BaseQueue
- type BatchError
- type Condition
- func ColumnEquals(column string, value any) Condition
- func DataCondition(key string, op ConditionOperator, value any) Condition
- func DataEquals(key string, value any) Condition
- func DataIsNotNull(key string) Condition
- func DataIsNull(key string) Condition
- func DataJSONCondition(keys []string, op ConditionOperator, value any) Condition
- func DataNotEquals(key string, value any) Condition
- func DataPathCondition(keys []string, op ConditionOperator, value any) Condition
- func DeletedAtIsNull() Condition
- func IDEquals(id any) Condition
- func NewCondition(field string, op ConditionOperator, value any) Condition
- func NewJSONCondition(field, key string, op ConditionOperator, value any) Condition
- func NewJSONPathCondition(field string, keys []string, op ConditionOperator, value any, jsonObj bool) Condition
- func StatusEquals(status string) Condition
- type ConditionOperator
- type Consumer
- type ConsumerError
- type ConsumerFactory
- type Hooks
- type MaxRetriesExceededError
- type PgQueue
- func (q *PgQueue) BeginTx(ctx context.Context) (pgx.Tx, context.Context, context.CancelFunc, error)
- func (q *PgQueue) CheckCondition(ctx context.Context, tx pgx.Tx, conditions ...Condition) (bool, error)
- func (q *PgQueue) Dequeue(batchSize int) (tasks []Task, err error)
- func (q *PgQueue) Drain(ctx context.Context) error
- func (q *PgQueue) Enqueue(task Task, tx pgx.Tx) error
- func (q *PgQueue) GetRetryPolicy(ctx context.Context) (*RetryPolicy, error)
- func (q *PgQueue) IsPaused(ctx context.Context) (bool, error)
- func (q *PgQueue) Pause(ctx context.Context) error
- func (q *PgQueue) QueueLabel() string
- func (q *PgQueue) Resume(ctx context.Context) error
- func (q *PgQueue) Select(ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod) error
- func (q *PgQueue) SelectOne(ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod) (bool, error)
- func (q *PgQueue) UpdateEntry(task Task, tx pgx.Tx, conditions ...Condition) error
- func (q *PgQueue) UpdateStatus(ctx context.Context, tx pgx.Tx, status string, conditions ...Condition) error
- type PgQueueOption
- type Queue
- type QueueData
- type QueueDefinition
- type RetryPolicy
- type SchemaManager
- func (sm *SchemaManager) EnsureQueue(ctx context.Context, name, dlqName string) error
- func (sm *SchemaManager) EnsureSchema(ctx context.Context) error
- func (sm *SchemaManager) Migrate(ctx context.Context, queues []QueueDefinition) error
- func (sm *SchemaManager) MigrateDown(ctx context.Context, steps int) error
- func (sm *SchemaManager) MigrateDownAll(ctx context.Context) error
- func (sm *SchemaManager) MigrateDownQueue(ctx context.Context, queueName string, steps int) error
- func (sm *SchemaManager) MigrateDownQueueAll(ctx context.Context, queueName string) error
- func (sm *SchemaManager) MigrateWithStatus(ctx context.Context, queues []QueueDefinition) (bool, error)
- type SchemaManagerOption
- type SelectMod
- type SelectQuery
- type SlogHooks
- func (h SlogHooks) OnDLQ(ctx context.Context, taskID, reason string)
- func (h SlogHooks) OnDLQFailed(ctx context.Context, taskID string, err error)
- func (h SlogHooks) OnDequeue(ctx context.Context, queueName string, count int)
- func (h SlogHooks) OnEnqueue(ctx context.Context, queueName, entryID string)
- func (h SlogHooks) OnQueueDrained(ctx context.Context, queueName string)
- func (h SlogHooks) OnQueuePaused(ctx context.Context, queueName string)
- func (h SlogHooks) OnQueueResumed(ctx context.Context, queueName string)
- func (h SlogHooks) OnRetry(ctx context.Context, taskID string, attempt int, nextRunAt time.Time)
- func (h SlogHooks) OnTaskComplete(ctx context.Context, taskID string, duration time.Duration)
- func (h SlogHooks) OnTaskStart(ctx context.Context, taskID string)
- type Task
- type TaskError
- type TaskRetryPolicySelector
- type TaskStatus
- type UpdateMod
- type UpdateQuery
- type Worker
- func (w *Worker) DlqEnqueue(ctx context.Context, task *Task, tx pgx.Tx) (err error)
- func (w *Worker) GetRetrySchedule(task *Task, retryPolicy *RetryPolicy) (time.Time, error)
- func (w *Worker) HandleFailure(ctx context.Context, task *Task, failure error, tx pgx.Tx, start time.Time) error
- func (w *Worker) HandleProcessed(ctx context.Context, task *Task, status TaskStatus, tx pgx.Tx, start time.Time) (err error)
- func (w *Worker) HandleUnit(ctx context.Context, task *Task, consumer Consumer) error
- func (w *Worker) Poll(ctx context.Context) (tasks []Task, err error)
- func (w *Worker) Retry(ctx context.Context, task *Task, tx pgx.Tx) (err error)
- func (w *Worker) Run(ctx context.Context, factory ConsumerFactory, interval time.Duration) error
- func (w *Worker) Stop()
- func (w *Worker) Work(ctx context.Context, factory ConsumerFactory) error
- type WorkerConfig
Constants ¶
const ( StrategyFixed = "fixed" StrategyExponential = "exponential" StrategyLinear = "linear" )
Retry strategy constants define the back-off algorithms available for task retries.
Variables ¶
var ErrQueueDraining = fmt.Errorf("queue is draining")
ErrQueueDraining is returned when an operation is attempted on a draining queue. Use errors.Is(err, ErrQueueDraining) to check for this condition.
var ErrQueuePaused = fmt.Errorf("queue is paused")
ErrQueuePaused is returned when an operation is attempted on a paused queue. Use errors.Is(err, ErrQueuePaused) to check for this condition.
Functions ¶
func ParseRetryStrategy ¶
ParseRetryStrategy validates and normalises a retry strategy string. An empty string is treated as the default exponential strategy.
Types ¶
type BaseHooks ¶
type BaseHooks struct{}
BaseHooks is a no-op Hooks implementation. Embed it in your own struct to selectively override only the hooks you care about.
func (BaseHooks) OnDLQFailed ¶
OnDLQFailed is a no-op implementation.
func (BaseHooks) OnQueueDrained ¶
OnQueueDrained is a no-op implementation.
func (BaseHooks) OnQueuePaused ¶
OnQueuePaused is a no-op implementation.
func (BaseHooks) OnQueueResumed ¶
OnQueueResumed is a no-op implementation.
func (BaseHooks) OnTaskComplete ¶
OnTaskComplete is a no-op implementation.
type BaseQueue ¶
type BaseQueue struct {
Ctx context.Context
Schema string
QueueName string
RetryPolicy *RetryPolicy
TxTimeout time.Duration // default 5s; applied to every transaction begin
}
BaseQueue holds the shared configuration for all queue implementations.
func (BaseQueue) QualifiedQueueName ¶
QualifiedQueueName returns the schema-qualified queue table name.
type BatchError ¶
type BatchError struct {
Total int // tasks attempted
Failed int // tasks that errored
Errors []*TaskError // individual failures
}
BatchError aggregates task errors from a single Work() batch.
func (*BatchError) Error ¶
func (e *BatchError) Error() string
func (*BatchError) Unwrap ¶
func (e *BatchError) Unwrap() []error
type Condition ¶
type Condition struct {
Field string // e.g., "data", "id", "status", "deleted_at"
Keys []string // JSON path segments, e.g. ["config", "settings", "theme"]
JSONText bool // If true, last key uses ->> (text extraction); if false, uses -> (JSON)
Operator ConditionOperator // The comparison operator
Value any // nil for IS NULL/IS NOT NULL operators
}
Condition describes a single WHERE-clause filter for queue task queries.
func ColumnEquals ¶
ColumnEquals creates a Condition that checks equality on a plain column.
func DataCondition ¶
func DataCondition(key string, op ConditionOperator, value any) Condition
DataCondition creates a Condition for a JSON text extraction on the data column.
func DataEquals ¶
DataEquals creates a Condition that checks equality on a data JSON key.
func DataIsNotNull ¶
DataIsNotNull creates a Condition that checks a data JSON key is not null.
func DataIsNull ¶
DataIsNull creates a Condition that checks a data JSON key is null.
func DataJSONCondition ¶
func DataJSONCondition(keys []string, op ConditionOperator, value any) Condition
DataJSONCondition creates a Condition for a JSON object path on the data column.
func DataNotEquals ¶
DataNotEquals creates a Condition that checks inequality on a data JSON key.
func DataPathCondition ¶
func DataPathCondition(keys []string, op ConditionOperator, value any) Condition
DataPathCondition creates a Condition for a deep JSON text path on the data column.
func DeletedAtIsNull ¶
func DeletedAtIsNull() Condition
DeletedAtIsNull creates a Condition that filters for non-deleted tasks.
func NewCondition ¶
func NewCondition(field string, op ConditionOperator, value any) Condition
NewCondition creates a Condition for a plain column comparison.
func NewJSONCondition ¶
func NewJSONCondition(field, key string, op ConditionOperator, value any) Condition
NewJSONCondition creates a Condition that extracts a single JSON key as text.
func NewJSONPathCondition ¶
func NewJSONPathCondition(field string, keys []string, op ConditionOperator, value any, jsonObj bool) Condition
NewJSONPathCondition creates a Condition that traverses a multi-segment JSON path.
func StatusEquals ¶
StatusEquals creates a Condition that filters tasks by status.
func (*Condition) ApplyToSelect ¶
func (c *Condition) ApplyToSelect(query SelectQuery)
ApplyToSelect adds this condition as a WHERE clause to a SELECT query.
func (*Condition) ApplyToUpdate ¶
func (c *Condition) ApplyToUpdate(query UpdateQuery)
ApplyToUpdate adds this condition as a WHERE clause to an UPDATE query.
type ConditionOperator ¶
type ConditionOperator string
ConditionOperator represents a SQL comparison or logical operator.
const ( OpEqual ConditionOperator = "=" OpNotEqual ConditionOperator = "!=" OpGreaterThan ConditionOperator = ">" OpLessThan ConditionOperator = "<" OpGreaterEq ConditionOperator = ">=" OpLessEq ConditionOperator = "<=" OpLike ConditionOperator = "LIKE" OpIsNull ConditionOperator = "IS NULL" OpIsNotNull ConditionOperator = "IS NOT NULL" OpIn ConditionOperator = "IN" OpNotIn ConditionOperator = "NOT IN" OpAnd ConditionOperator = "AND" OpOr ConditionOperator = "OR" OpNot ConditionOperator = "NOT" OpExists ConditionOperator = "EXISTS" OpNotExists ConditionOperator = "NOT EXISTS" OpBetween ConditionOperator = "BETWEEN" OpNotBetween ConditionOperator = "NOT BETWEEN" OpILike ConditionOperator = "ILIKE" OpNotILike ConditionOperator = "NOT ILIKE" OpIRegexp ConditionOperator = "~*" OpNotIRegexp ConditionOperator = "!~*" OpRegexp ConditionOperator = "~" OpNotRegexp ConditionOperator = "!~" OpJSONGet ConditionOperator = "->" OpJSONGetText ConditionOperator = "->>" )
Supported SQL operators for use in Condition filters.
type ConsumerError ¶
ConsumerError wraps an error returned by a Consumer with transience metadata.
func (*ConsumerError) Error ¶
func (e *ConsumerError) Error() string
func (*ConsumerError) Unwrap ¶
func (e *ConsumerError) Unwrap() error
type ConsumerFactory ¶
type ConsumerFactory func() Consumer
ConsumerFactory creates a new Consumer instance for each work cycle.
type Hooks ¶
type Hooks interface {
OnEnqueue(ctx context.Context, queueName, entryID string)
OnDequeue(ctx context.Context, queueName string, count int)
OnTaskStart(ctx context.Context, taskID string)
OnTaskComplete(ctx context.Context, taskID string, duration time.Duration)
OnRetry(ctx context.Context, taskID string, attempt int, nextRunAt time.Time)
OnDLQ(ctx context.Context, taskID, reason string)
OnDLQFailed(ctx context.Context, taskID string, err error)
OnQueuePaused(ctx context.Context, queueName string)
OnQueueResumed(ctx context.Context, queueName string)
OnQueueDrained(ctx context.Context, queueName string)
}
Hooks defines lifecycle callbacks for observability. Implement this interface to integrate custom logging, metrics, or tracing into the worker. Embed BaseHooks to selectively override only the methods you need.
type MaxRetriesExceededError ¶
MaxRetriesExceededError indicates a task has exceeded its maximum retry count.
func (*MaxRetriesExceededError) Error ¶
func (e *MaxRetriesExceededError) Error() string
type PgQueue ¶
PgQueue is a PostgreSQL-backed queue that stores and retrieves entries using pgxpool transactions.
func NewPgQueue ¶
func NewPgQueue(ctx context.Context, pool *pgxpool.Pool, queueName string, retryPolicy *RetryPolicy, opts ...PgQueueOption) (*PgQueue, error)
NewPgQueue validates its inputs and constructs a PgQueue. A non-nil error is returned when any required argument is missing or the retry policy is invalid.
func (*PgQueue) CheckCondition ¶
func (q *PgQueue) CheckCondition(ctx context.Context, tx pgx.Tx, conditions ...Condition) (bool, error)
CheckCondition returns true when at least one row matches all conditions.
func (*PgQueue) Dequeue ¶
Dequeue claims up to batchSize pending tasks atomically, setting them to RUNNING.
func (*PgQueue) Enqueue ¶
Enqueue inserts a queue entry into the queue table within the given transaction.
func (*PgQueue) GetRetryPolicy ¶
func (q *PgQueue) GetRetryPolicy(ctx context.Context) (*RetryPolicy, error)
GetRetryPolicy returns the queue's retry policy, loading it from the database on first access if no static policy was provided at construction time.
func (*PgQueue) QueueLabel ¶
QueueLabel returns the queue's table name for display/logging purposes.
func (*PgQueue) Select ¶
func (q *PgQueue) Select( ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod, ) error
Select builds and executes a SELECT against the queue table. sm.From is always prepended automatically so callers don't need it. scan is called once per row; returning an error stops iteration immediately. All filtering, ordering, and column selection is expressed as SelectMods (e.g. sm.Where, sm.OrderBy, sm.Limit, sm.Columns).
func (*PgQueue) SelectOne ¶
func (q *PgQueue) SelectOne( ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod, ) (bool, error)
SelectOne executes a SELECT and calls scan for the first matching row. Returns (true, nil) when a row was found, (false, nil) when none matched. scan receives a pgx.Rows already positioned on the row — call rows.Scan() directly inside it.
func (*PgQueue) UpdateEntry ¶
UpdateEntry persists changes to a queue entry within the given transaction.
type PgQueueOption ¶
type PgQueueOption func(*pgQueueConfig)
PgQueueOption configures a PgQueue during construction.
func WithAutoMigrate ¶
func WithAutoMigrate() PgQueueOption
WithAutoMigrate enables automatic schema migration on queue creation.
func WithDLQName ¶
func WithDLQName(name string) PgQueueOption
WithDLQName overrides the DLQ table name used by WithAutoMigrate. When unset, liteq derives "<queue>_dead_letter" for non-DLQ queues.
func WithSchema ¶
func WithSchema(schema string) PgQueueOption
WithSchema sets the PostgreSQL schema for queue tables.
type Queue ¶
type Queue interface {
Enqueue(task Task, tx pgx.Tx) error
Dequeue(batchSize int) ([]Task, error)
UpdateEntry(task Task, tx pgx.Tx, conditions ...Condition) error
CheckCondition(ctx context.Context, tx pgx.Tx, conditions ...Condition) (bool, error)
Select(ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod) error
SelectOne(ctx context.Context, scan func(pgx.Rows) error, mods ...SelectMod) (bool, error)
UpdateStatus(ctx context.Context, tx pgx.Tx, status string, conditions ...Condition) error
GetRetryPolicy(ctx context.Context) (*RetryPolicy, error)
BeginTx(ctx context.Context) (pgx.Tx, context.Context, context.CancelFunc, error)
QueueLabel() string
// Queue state management.
Pause(ctx context.Context) error
Resume(ctx context.Context) error
IsPaused(ctx context.Context) (bool, error)
Drain(ctx context.Context) error
}
Queue defines the stable queue operations supported by liteq backends.
The method set mirrors the current PgQueue API so callers can depend on an interface without forcing a breaking rewrite of the package surface.
type QueueDefinition ¶
QueueDefinition specifies a queue and its dead-letter queue migration behavior.
type RetryPolicy ¶
type RetryPolicy struct {
Strategy string `json:"strategy"`
MaxRetries int `json:"maxRetries"`
RetryDelayMs int `json:"retryDelayMs"`
MaxDelayMs int `json:"maxDelayMs"`
}
RetryPolicy configures the back-off behavior for failed tasks.
type SchemaManager ¶
type SchemaManager struct {
// contains filtered or unexported fields
}
SchemaManager handles database migrations for liteq queue tables.
func NewSchemaManager ¶
func NewSchemaManager(pool *pgxpool.Pool, opts ...SchemaManagerOption) *SchemaManager
NewSchemaManager creates a SchemaManager with the given pool and options.
func (*SchemaManager) EnsureQueue ¶
func (sm *SchemaManager) EnsureQueue(ctx context.Context, name, dlqName string) error
EnsureQueue applies migrations for a single queue and its optional DLQ.
func (*SchemaManager) EnsureSchema ¶
func (sm *SchemaManager) EnsureSchema(ctx context.Context) error
EnsureSchema applies only the foundation migration (schema + migrations table).
func (*SchemaManager) Migrate ¶
func (sm *SchemaManager) Migrate(ctx context.Context, queues []QueueDefinition) error
Migrate applies all pending up-migrations for the given queue definitions.
func (*SchemaManager) MigrateDown ¶
func (sm *SchemaManager) MigrateDown(ctx context.Context, steps int) error
MigrateDown rolls back the given number of migration batches.
func (*SchemaManager) MigrateDownAll ¶
func (sm *SchemaManager) MigrateDownAll(ctx context.Context) error
MigrateDownAll rolls back all applied migration batches.
func (*SchemaManager) MigrateDownQueue ¶
MigrateDownQueue rolls back the given number of migration batches for a single queue.
func (*SchemaManager) MigrateDownQueueAll ¶
func (sm *SchemaManager) MigrateDownQueueAll(ctx context.Context, queueName string) error
MigrateDownQueueAll rolls back all applied migration batches for a single queue.
func (*SchemaManager) MigrateWithStatus ¶
func (sm *SchemaManager) MigrateWithStatus(ctx context.Context, queues []QueueDefinition) (bool, error)
MigrateWithStatus applies all pending up-migrations for the given queue definitions and reports whether any new migration records were applied.
type SchemaManagerOption ¶
type SchemaManagerOption func(*schemaManagerConfig)
SchemaManagerOption configures a SchemaManager at construction time.
func WithDryRun ¶
func WithDryRun(w io.Writer) SchemaManagerOption
WithDryRun enables dry-run mode, writing SQL to w instead of executing it.
func WithSchemaManagerSchema ¶
func WithSchemaManagerSchema(schema string) SchemaManagerOption
WithSchemaManagerSchema sets the target Postgres schema for migrations.
type SelectMod ¶
type SelectMod = bob.Mod[*dialect.SelectQuery]
SelectMod is a query modifier for PostgreSQL SELECT statements.
type SelectQuery ¶
type SelectQuery interface {
Apply(mods ...SelectMod)
}
SelectQuery is a SELECT query builder that accepts SelectMod modifiers.
type SlogHooks ¶
SlogHooks emits structured log lines via slog for each lifecycle event.
func (SlogHooks) OnDLQFailed ¶
OnDLQFailed logs a dead-letter queue enqueue failure.
func (SlogHooks) OnQueueDrained ¶
OnQueueDrained logs a queue drain event.
func (SlogHooks) OnQueuePaused ¶
OnQueuePaused logs a queue pause event.
func (SlogHooks) OnQueueResumed ¶
OnQueueResumed logs a queue resume event.
func (SlogHooks) OnTaskComplete ¶
OnTaskComplete logs a task completion event with duration.
type Task ¶
type Task struct {
ID string `json:"id" db:"id"`
Data QueueData `json:"data" db:"data"`
Status string `json:"status" db:"status"`
IsRetry bool `json:"isRetry" db:"is_retry"`
Retries int `json:"retries" db:"retries"`
RetryPolicy *RetryPolicy `json:"retryPolicy" db:"retry_policy"`
NextRunAt *time.Time `json:"nextRunAt" db:"next_run_at"`
LastRunAt *time.Time `json:"lastRunAt" db:"last_run_at"`
ProcessedAt *time.Time `json:"processedAt" db:"processed_at"`
EnqueuedAt *time.Time `json:"enqueued_at" db:"enqueued_at"`
DequeuedAt *time.Time `json:"dequeued_at" db:"dequeued_at"`
CreatedAt *time.Time `json:"created_at" db:"created_at"`
UpdatedAt *time.Time `json:"updated_at" db:"updated_at"`
DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"`
}
Task is a queue entry representing a unit of work to be processed. ID stores the canonical UUID string for the queue row. Leave it empty on enqueue to let PostgreSQL generate a new UUID.
func (*Task) WillExceedMaxRetries ¶
WillExceedMaxRetries reports whether the next retry would exceed maxRetries.
type TaskRetryPolicySelector ¶
type TaskRetryPolicySelector func(task Task) (*RetryPolicy, error)
TaskRetryPolicySelector resolves the retry policy for a given task. Returning (nil, nil) indicates that no retries are allowed.
type TaskStatus ¶
type TaskStatus string
TaskStatus represents the lifecycle state of a task in the queue.
const ( PENDING TaskStatus = "PENDING" RUNNING TaskStatus = "RUNNING" FAILED TaskStatus = "FAILED" COMPLETED TaskStatus = "COMPLETED" CANCELLED TaskStatus = "CANCELLED" //nolint:misspell // CANCELLED is the stored DB value DLQFailed TaskStatus = "DLQ_FAILED" )
Task status constants represent all possible states in a task's lifecycle.
type UpdateMod ¶
type UpdateMod = bob.Mod[*dialect.UpdateQuery]
UpdateMod is a query modifier for PostgreSQL UPDATE statements.
type UpdateQuery ¶
type UpdateQuery interface {
Apply(mods ...UpdateMod)
}
UpdateQuery is an UPDATE query builder that accepts UpdateMod modifiers.
type Worker ¶
type Worker struct {
Ctx context.Context
TaskBatchSize int
TaskQueue Queue
DeadLetterQueue Queue
GetTaskRetryPolicy TaskRetryPolicySelector
MaxConcurrency int
TaskTimeout time.Duration
// contains filtered or unexported fields
}
Worker dequeues tasks from a queue, processes them via a Consumer, and handles retries and dead-letter enqueueing on failure.
func NewWorker ¶
func NewWorker(ctx context.Context, config *WorkerConfig) (*Worker, error)
NewWorker validates config and constructs a Worker. A non-nil error is returned when any required field is missing or has an invalid value.
func (*Worker) DlqEnqueue ¶
DlqEnqueue sends a failed task to the dead-letter queue within the given transaction.
func (*Worker) GetRetrySchedule ¶
GetRetrySchedule calculates the next run time for a task based on the retry policy strategy. Supported strategies are fixed, linear, and exponential (default). A jitter in the range [0, delayMs] is applied to spread load.
func (*Worker) HandleFailure ¶
func (w *Worker) HandleFailure(ctx context.Context, task *Task, failure error, tx pgx.Tx, start time.Time) error
HandleFailure marks a task as failed and either retries or dead-letters it.
func (*Worker) HandleProcessed ¶
func (w *Worker) HandleProcessed(ctx context.Context, task *Task, status TaskStatus, tx pgx.Tx, start time.Time) (err error)
HandleProcessed persists the task's new status and fires completion hooks.
func (*Worker) HandleUnit ¶
HandleUnit runs the consumer for one task with a deadline, then commits the result (completed, retry, or DLQ) inside a transaction. A timeout is treated as a transient failure and follows the normal retry path.
func (*Worker) Run ¶
Run polls in a loop until Stop() is called or ctx is canceled. Errors from individual Work() batches are logged but do not abort the loop.
type WorkerConfig ¶
type WorkerConfig struct {
TaskBatchSize int
TaskQueue Queue
DeadLetterQueue Queue
GetTaskRetryPolicy TaskRetryPolicySelector
MaxConcurrency int // default: runtime.NumCPU()
TaskTimeout time.Duration // default: 30s
Hooks Hooks // default: BaseHooks{} (silent)
}
WorkerConfig holds the configuration used to construct a Worker.