- Every strategy: Schedule jobs at fixed intervals measured in milliseconds
- Cron strategy: Use cron expressions for intricate scheduling patterns
Every Strategy
The every strategy is used when you want to produce repeatable jobs at specific intervals:Common Intervals
number
required
Interval in milliseconds between job executions
You cannot use both
pattern and every options together. Choose one strategy per scheduler.Cron Strategy
The cron strategy leverages the cron-parser library to use cron expressions for scheduling jobs with greater specificity. This approach is ideal for jobs requiring execution at precise times or intervals, such as automated reports or maintenance tasks.Cron Expression Format
BullMQ supports a 6-field cron format with an optional seconds field:Basic Example
Common Cron Patterns
string
required
Cron expression for scheduling (e.g., ‘0 * * * *’ for every hour)
Timezone Support
Cron expressions support timezone differences and daylight saving time transitions, crucial for tasks that depend on local times:Special Characters
Cron patterns support special characters for flexible scheduling:*- Any value,- Value list separator (e.g.,1,3,5)-- Range of values (e.g.,1-5)/- Step values (e.g.,*/5for every 5 units)L- Last day of the month (day field only)
If you’re new to cron expressions, Wikipedia is an excellent starting point to learn how to use them.
Custom Strategy
It’s possible to define a different strategy to schedule repeatable jobs. The idea is that the repeat strategy, based on a pattern and the latest job’s milliseconds, returns the next desired timestamp.Implementation Requirements
A custom repeat strategy is a function with this signature:- millis: Current timestamp in milliseconds
- opts: Repeat options containing pattern and other settings
- jobName: Name of the job (for conditional logic)
- Returns: Next execution timestamp in milliseconds, or undefined to stop
RRULE Example
Here’s an example using RRULE for complex recurrence patterns:Custom Strategy Best Practices
1
Handle edge cases
Return
undefined when no more jobs should be scheduled:2
Respect startDate
Always check if startDate is in the future:
3
Use job name for conditional logic
Different jobs can have different scheduling behavior:
4
Configure in both Queue and Worker
Ensure consistent behavior across your application:
Default Repeat Strategy
BullMQ’s default repeat strategy for cron patterns:Comparison
Related Topics
Repeat Options
Configure start dates, end dates, limits, and more
Overview
Learn the basics of Job Schedulers
Management
Manage and monitor job schedulers
