Skip to content
Get started
Get started
The Job Object Inside a Worker Processor
guide · worker

Everything the processor gets handed.

The job is more than its payload: attempt counts, timestamps, progress reporting, its own log stream, and the results of any children that ran before it.

Inside the processor you get the full job:

const worker = new Worker('queue', async (job) => {
job.id; // Job ID
job.name; // Job name
job.data; // Job data (typed if you use Worker<T>)
job.attemptsMade; // Current attempt number
job.timestamp; // When the job was created
await job.updateProgress(50, 'Halfway done'); // Report progress
await job.log('Processing step 1'); // Attach a log line
return result;
}, { embedded: true });

The Bun client can disable the automatic loop and explicitly acquire one job:

const worker = new Worker<{ value: number }, number>(
'calculations',
async (job) => job.data.value * 2,
{ autorun: false }
);
const job = await worker.getNextJob();
if (job) {
job.name; // the job name, separate from user data
job.data; // { value: number }
job.token; // broker lease token when useLocks is enabled
await worker.processJobManually(job);
}

processJobManually(job) reuses the lease tracked by getNextJob(), so the token argument can be omitted. If you pass an explicit token, it must match the current delivery.

Ownership-changing methods inside a processor

Section titled “Ownership-changing methods inside a processor”

When a Bun processor calls retry(), changeDelay(), moveToWait(), moveToDelayed(), or moveToWaitingChildren(), the confirmed broker transition consumes that delivery generation. Returning or throwing afterward does not send a second ACK or FAIL and does not emit a contradictory local terminal event. A rejected transition still follows normal processor failure handling.

job.discard() is synchronous for API compatibility, but the Worker tracks and awaits its broker command internally. Graceful shutdown therefore waits for the discard, repeated calls send one command, and a stale processor’s lease token cannot discard a newer active generation. An already-retired job is silent; an actual discard transport or engine failure emits one Worker error with context: 'discard' and leaves broker recovery in charge.

WorkerCreate a worker and process your first job
Worker Concurrency and Batch PullingRun jobs in parallel and pull them in batches
Worker Eventscompleted, failed, stalled and the rest
Worker Error Handling, Retries and BackoffRetries, backoff, timeouts and giving up
Worker LifecyclePause, resume and shut down without losing work
Heartbeats, Stall Detection and Lock OwnershipHeartbeats, stall recovery and lock ownership
SandboxedWorkerExperimental isolation for CPU-heavy handlers
WorkerOptions ReferenceEvery WorkerOptions field, with defaults