Skip to main content
The most important method of the Queue class is add, which allows you to add jobs to the queue in different ways.

Basic Usage

Adding a job is straightforward:
The job will now be stored in Redis, waiting for a worker to pick it up and process it. Workers may not be running when you add the job, but as soon as one worker is connected to the queue, it will pick up the job and process it.

Method Signature

string
required
Name of the job to be added to the queue
T
Arbitrary data to append to the job. This will be available in the worker’s processor function.
JobsOptions
Job options that affect how the job is processed. See below for available options.

Job Options

Timing Options

number
default:"0"
An amount of milliseconds to wait until this job can be processed. The job will be in the “delayed” state until the delay expires.
number
default:"Date.now()"
Timestamp when the job was created

Priority

number
default:"0"
Ranges from 0 (highest priority) to 2,097,152 (lowest priority). Note that using priorities has a slight impact on performance, so only use it if required.

Retry Options

number
default:"1"
The total number of attempts to try the job until it completes
number | BackoffOptions
Backoff setting for automatic retries if the job fails. Can be a number (milliseconds) or an object with type and delay.

Auto-Removal Options

boolean | number | KeepJobs
If true, removes the job when it successfully completes. When given a number, it specifies the maximum amount of jobs to keep. You can also provide an object specifying max age and/or count to keep.
boolean | number | KeepJobs
If true, removes the job when it fails after all attempts. When given a number, it specifies the maximum amount of jobs to keep. You can also provide an object specifying max age and/or count to keep.

Job Identification

string
Override the job ID. By default, the job ID is a unique integer, but you can use this setting to override it. If you use this option, it is up to you to ensure the jobId is unique. If you attempt to add a job with an ID that already exists, it will not be added (a ‘duplicated’ event will be emitted instead).
JobId cannot be ‘0’ or start with ‘0:‘

Processing Options

boolean
default:"false"
If true, adds the job to the right of the queue instead of the left, making it a LIFO (Last In First Out) queue.

Logging Options

number
Maximum amount of log entries that will be preserved for this job
number
Limits the amount of stack trace lines that will be recorded in the stacktrace when the job fails

Size Limits

number
Limits the size in bytes of the job’s data payload (as a JSON serialized string)

Parent-Child Jobs

ParentOptions
Parent options for creating parent-child job relationships. Allows you to create flows where child jobs must complete before the parent job can proceed.

Repeatable Jobs

RepeatOptions
Repeat this job based on a cron schedule or interval.

Complete Example