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
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:
Delay in milliseconds before the job can be processed
Job priority (0 is highest priority)
Number of retry attempts
Backoff settings for retries
Add to right of queue (LIFO) instead of left (FIFO)
Auto-remove job on completion
Auto-remove job on failure
Custom job ID (must be unique)
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
