Overview
The Queue constructor creates a new queue that is persisted in Redis. Every time the same queue is instantiated, it attempts to process all old jobs that may exist from a previous unfinished session.Signature
Parameters
The name of the queue. Multiple queue instances with the same name will share the same job data.
Redis connection string. For example:
redis://mypassword@myredis.server.com:1234Configuration options for the queue.
Custom function to create Redis client instances. Receives Note: The ‘bclient’ (blocking client) connection cannot be shared and a new connection should be returned each time.
type (‘client’, ‘subscriber’, or ‘bclient’) and optional Redis config.Rate limiting configuration.
Maximum number of jobs processed per duration.
Duration in milliseconds for the rate limit window.
When jobs get rate limited, they stay in the waiting queue instead of moving to delayed queue.
Allows grouping of jobs with the specified key from the data object (e.g., “network.handle”).
Prefix for all queue keys in Redis.
Configure metrics collection.
Maximum number of data points to collect. Granularity is fixed at one minute.
Default options to apply to all jobs added to the queue.
Advanced queue behavior settings.
Key expiration time for job locks in milliseconds.
Interval in milliseconds on which to renew the job lock.
How often to check for stalled jobs in milliseconds. Use 0 to never check.
Maximum number of times a stalled job will be re-processed.
Poll interval for delayed jobs and added jobs in milliseconds.
Delay before processing next job in case of internal error.
A set of custom backoff strategies keyed by name.
Timeout for when the queue is in drained state (empty waiting for jobs).
Enables multiple queues on the same instance of child pool to share the same instance.
Examples
Basic Queue
Queue with Redis URL
Queue with Redis Options
Queue with Rate Limiting
Queue with Custom Backoff Strategy
Queue with Shared Redis Connections
Queue with Metrics
Advanced Settings Notes
Lock Duration
Set this to a higher value if your jobs are CPU-intensive and blocking the event loop. Set to a lower value if jobs are extremely time-sensitive and it might be acceptable if they get double-processed.Stalled Interval
Set this to a lower value if your jobs are extremely time-sensitive. Set this to a higher value if your Redis CPU usage is high, as this check can be expensive.Guard Interval
When running multiple concurrent workers with delayed tasks, set this value much higher (e.g.,numberOfWorkers * 5000) to avoid spikes in network bandwidth, CPU usage, and memory usage.
Max Stalled Count
Set this higher if stalled jobs are common (e.g., processes crash frequently) and it’s generally acceptable to double-process jobs.Queue.isReady()
Returns a promise that resolves when the queue is ready to accept jobs. This is useful when you need to ensure the queue has finished initializing before adding jobs.Signature
Returns
A promise that resolves to the Queue instance when ready.
Example
Usage in Initialization
Most of the time you don’t need to call
isReady() explicitly, as methods like add() and process() will wait for the queue to be ready internally.