Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Worker Configuration

WorkerConfig holds the handler, thread count, timings, and callbacks. Set fields before the pool starts.

poolConfigForWorkers sizes the database pool for a list of worker pools. Pass the same list to poolConfigForWorkers, runWorkerPools, and shutdownWorkerPools.

Multiple Queues

One pool per queue, named with namedWorkerPool:

let workers = [Worker.namedWorkerPool emailConfig, Worker.namedWorkerPool imageConfig]

When one pool exits, the others stop. runWorkerPools then throws the first failure.

ARBITER_ENABLED_QUEUES selects pools by name. Unset, every pool starts. An unknown name throws at startup.

ARBITER_ENABLED_QUEUES=email_queue,image_queue

Configuration Types

ConstructorTransactionFinalization
transactionalWorkerConfigwraps the handlera return acks and stores the result. An exception rolls back, then retries or moves to the DLQ.
manualWorkerConfignonecallbacks, one job per call
batchedWorkerConfignonecallbacks, up to batchSize jobs per call

A manual or batched handler must ack, fail, or nack each job:

HandlerUnfinalized job
returnsredelivered after its lease expires
throwsfails, then retries or moves to the DLQ

A nack consumes no attempt. The job is redelivered after its lease expires.

withDbTransaction around a callback commits the ack with the application writes. Inside an outer transaction the callback is a savepoint. onJobSuccess fires at the savepoint release, before the outer commit.

Timings

FieldMeaning
visibilityTimeoutthe lease length: how long a claim holds a job
jobHeartbeatIntervalhow often the worker renews the hold
maxJobDurationlongest a handler can run

Timing details: Leases and Deadlines. Field reference: WorkerConfig Haddocks.