Queue.add()
Creates a new job and adds it to the queue. If the queue is empty, the job will be executed directly. Otherwise, it will be placed in the queue and executed as soon as possible.Signature
Parameters
Optional name for the job (also called job type). Only process functions defined for this name will process the job.
The job data. This object will be available as
job.data in the processor function.Job options.
Priority value ranging from 1 (highest) to MAX_INT (lowest). Using priorities has a slight performance impact.
Milliseconds to wait before this job can be processed. For accurate delays, ensure server and client clocks are synchronized.
Total number of attempts to try the job until it completes.
Repeat job according to a schedule.
Cron expression for the schedule.
Timezone for cron expression.
Start date when the repeat job should start (only with cron).
End date when the repeat job should stop repeating.
Number of times the job should repeat at maximum.
Repeat every X milliseconds. Cannot be used with cron setting.
Start value for the repeat iteration count.
Backoff setting for automatic retries if the job fails. Requires
attempts to be set.As number: Delay in milliseconds using fixed strategy.As object:Backoff type: ‘fixed’, ‘exponential’, or custom strategy name.
Backoff delay in milliseconds.
Options for custom backoff strategies.
If true, adds the job to the right of the queue (LIFO) instead of the left (FIFO).
Number of milliseconds after which the job should fail with a timeout error.
Override the job ID. By default, the job ID is a unique integer. You must ensure uniqueness when using this option.
If true, removes the job when it fails after all attempts. A number specifies the count of jobs to keep.
Limits the number of stack trace lines recorded in the stacktrace.
Returns
A promise that resolves to the created Job instance.
Examples
Basic Job
Named Job
Delayed Job
Job with Priority
Job with Retry Logic
Repeating Job (Cron)
Repeating Job (Interval)
Job with Timeout
Job with Custom ID
Auto-cleanup Completed Jobs
Keep Last N Jobs
Keep Jobs by Age
LIFO Queue
Queue.addBulk()
Creates multiple jobs and adds them to the queue in a single operation. This is more efficient than callingadd() multiple times.
Signature
Parameters
Array of job specifications. Each job follows the same signature as
Queue.add().Returns
A promise that resolves to an array of created Job instances.
Examples
Bulk Add Multiple Jobs
Bulk Add with Options
Bulk Add from Database Records
Important Notes
Named Jobs: You need to define processors for all named jobs you add, unless you use
'*' as the processor name.Repeatable Jobs: Adding a job with the
repeat option creates a Repeatable Job configuration AND schedules the first run. Repeatable jobs are not included in methods like getJobs(). Use getRepeatableJobs() instead.Job ID Uniqueness: When using
jobId, repeated jobs with different repeat options can have the same ID, but regular jobs cannot share IDs.Timeout Implementation
Jobs are NOT proactively stopped after the timeout. The job is marked as failed and the promise is rejected, but Bull cannot stop the processor function externally. To stop a job after timeout:- Have the job periodically check
job.getState()and exit if status becomes ‘failed’ - Implement the job as a cancelable promise with a
cancel()method - Add a listener for the ‘failed’ event and stop the job externally