Skip to main content
BullMQ comes with two predefined strategies for creating repeatable jobs:
  • Every strategy: Schedule jobs at fixed intervals measured in milliseconds
  • Cron strategy: Use cron expressions for intricate scheduling patterns
Additionally, BullMQ lets you create custom strategies, giving you the flexibility to define your own logic for setting job intervals.

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:
This format includes the optional second field, which is not typically available in standard cron schedules, allowing for even more precise scheduling.

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., */5 for 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.
Only one repeatStrategy can be defined for a given queue. The strategy applies to all job schedulers in that queue.

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:
The repeat strategy setting must be provided in both the Queue and Worker classes. The Queue uses it when first adding the job to calculate the next iteration. After that, the Worker uses its configured settings.

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

Repeat Options

Configure start dates, end dates, limits, and more

Overview

Learn the basics of Job Schedulers

Management

Manage and monitor job schedulers

API Reference