addBulk is more efficient than adding them one by one. This method reduces the number of roundtrips to Redis and ensures all jobs are added atomically.
Method Signature
array
required
An array of job definitions. Each job is defined by three properties:
name, data, and opts. They follow the same signature as Queue.add.Basic Usage
Adding Jobs with Options
Each job in the bulk array can have its own options, just like when usingadd:
Job Options
Theopts field for each job in the bulk array supports all the same options as the regular add method, except for the repeat option:
number
Delay in milliseconds before the job can be processed
number
Job priority (0 is highest priority)
number
Number of retry attempts
number | BackoffOptions
Backoff settings for retries
boolean
Add to right of queue (LIFO) instead of left (FIFO)
boolean | number | KeepJobs
Auto-remove job on completion
boolean | number | KeepJobs
Auto-remove job on failure
string
Custom job ID (must be unique)
ParentOptions
Parent job options for flows
Atomicity
TheaddBulk operation is atomic, meaning it will either succeed and add all jobs, or fail and add none of them:
Performance Benefits
UsingaddBulk provides significant performance improvements when adding multiple jobs:
- Reduced Network Roundtrips: One network call instead of many
- Atomic Operation: All-or-nothing guarantees
- Better Throughput: Can add thousands of jobs quickly
