Skip to main content
Workers are the core processing units in BullMQ that consume jobs from queues and execute your business logic. A worker is equivalent to a message receiver in traditional message queue systems.

Basic Worker Creation

Create a worker by instantiating the Worker class with a queue name and a processor function:

Processor Function Signature

The processor function receives up to three parameters:
  • job: The job instance containing data and methods
  • token: Optional lock token for the job
  • signal: Optional AbortSignal for job cancellation

Example with All Parameters

Worker Options

Configure worker behavior with options:

Key Options

concurrency
number
default:"1"
Number of jobs that can be processed in parallel. See Concurrency.
autorun
boolean
default:"true"
Whether to start processing jobs immediately upon worker creation.
lockDuration
number
default:"30000"
Duration in milliseconds that a worker holds a lock on a job.
maxStalledCount
number
default:"1"
Maximum times a job can be recovered from stalled state before moving to failed.
stalledInterval
number
default:"30000"
Interval in milliseconds between stalled job checks.
removeOnComplete
KeepJobs
Automatically remove completed jobs. See Auto-removal.
removeOnFail
KeepJobs
Automatically remove failed jobs. See Auto-removal.

Manual Worker Control

Control when the worker starts processing:

Worker Events

Listen to worker events to monitor job processing:
Always attach an error listener to prevent uncaught exceptions from crashing your application.

Progress Reporting

Report job progress from within the processor:

TypeScript Generics

Define types for job data and return values:

Waiting Until Ready

Wait for the worker’s Redis connection to be ready:

Graceful Shutdown

Properly close the worker:
See Graceful Shutdown for more details.

Global Job Events

Monitor jobs across all workers using QueueEvents:

Best Practices

1

Always handle errors

Attach an error listener to prevent crashes:
2

Keep processors async

Use async/await or return promises to avoid blocking the event loop.
3

Report progress for long jobs

Help monitor long-running jobs by calling job.updateProgress().
4

Handle shutdown gracefully

Call worker.close() on process termination:
5

Use sandboxing for CPU-intensive work

See Sandboxed Processors for CPU-heavy tasks.

Concurrency

Process multiple jobs in parallel

Sandboxed Processors

Isolate CPU-intensive processors

Graceful Shutdown

Properly close workers

Cancelling Jobs

Cancel jobs in progress

API Reference