Job Schedulers replace “repeatable jobs” and are available in v5.16.0 and onwards. They are the recommended approach for creating recurring jobs in BullMQ.
Creating a Job Scheduler
To create a scheduler, use theupsertJobScheduler method:
Key Concepts
Upsert vs. Add
Theupsert operation (update or insert) is used instead of add to simplify management of recurring jobs, especially in production deployments. It ensures the scheduler is updated or created without duplications.
Job Production Rate
The scheduler will only generate new jobs when the last job begins processing. Therefore:- If your queue is very busy
- If you don’t have enough workers or concurrency
- Jobs may be produced less frequently than the specified repetition interval
Job Status
As long as a Job Scheduler is producing jobs, there will always be one job associated with the scheduler in the “Delayed” status, waiting to be processed.Using Job Templates
You can define a template with standard names, data, and options for jobs added to a queue. This ensures that all jobs produced by the Job Scheduler inherit these settings:upsertJobScheduler again with the same scheduler ID to update any settings of this particular job scheduler, such as the repeat options or job template settings.
Template Options
Job name for all produced jobs
Default data object passed to every job
Default job options (attempts, backoff, priority, etc.)
Job IDs
Since jobs produced by the Job Scheduler get a special job ID to guarantee that jobs will never be created more often than the given repeat settings, you cannot choose a custom job ID. However, you can use the job’s name to discriminate these jobs from other jobs.
repeat:{jobSchedulerId}:{nextMillis}
Complete Example
Best Practices
1
Use descriptive scheduler IDs
Choose meaningful IDs that describe the scheduler’s purpose:
2
Set appropriate job options
Configure attempts, backoff, and auto-removal for scheduled jobs:
3
Consider timezone for cron patterns
Always specify a timezone when using cron patterns:
4
Clean up unused schedulers
Remove schedulers that are no longer needed:
Related Topics
Repeat Strategies
Learn about every, cron, and custom repeat strategies
Repeat Options
Configure start dates, end dates, limits, and more
Management
Manage, retrieve, and remove job schedulers
RepeatableOptions
API reference for repeatable options
