Repeatable

There is a special type of meta job called repeatable. These jobs are special in the sense that even though you only add one job to the queue, they will keep repeating according to a predefined schedule.

Every time a repeatable job is picked up for processing, the next repeatable job is added to the queue with a proper delay. Repeatable jobs are thus nothing more than delayed jobs that are added to the queue according to some settings.

Repeatable jobs are just delayed jobs, therefore you also need a QueueScheduler instance to schedule the jobs accordingly.

There are two ways to specify a repeatable's job repetition pattern, either with a cron expression, or specifying a fix amount of milliseconds between repetitions.

import { Queue, QueueScheduler }Β from 'bullmq'
​
const myQueueScheduler = new QueueScheduler('Paint');
const myQueue = new Queue('Paint');
​
// Repeat job once every day at 3:15 (am)
await myQueue.add('submarine', { color: 'yellow' },
{
repeat: {
cron: '15 3 * * *'
}
});
​
// Repeat job every 10 seconds but no more than 100 times
await myQueue.add('bird', { color: 'bird' },
{
repeat: {
every: 10000,
limit: 100
}
});
​

​

There are some important considerations regarding repeatable jobs:

  • Bull is smart enough not to add the same repeatable job if the repeat options are the same.

  • If there are no workers running, repeatable jobs will not accumulate next time a worker is online.

  • repeatable jobs can be removed using the removeRepeatable method.

​