Search code examples
node.jsredisscheduled-tasksbullmqbull.js

How to handle repeatable jobs in Bull.js when the queue is paused


I am using Bull.js with repeatable jobs. I want to be able to pause the queue while I'm updating the server. I was planning to use pause method of Bull.js but what I realized is that once the queue is unpaused Bull.js only runs the repeatable jobs that was registered before the pause. So if there were some jobs that were supposed to run while the queue is paused they are just being ignored.

For example, I add a job in queue at 16:52 with repeat definition which triggers the job every 10 minutes. If I pause the queue at 16:55 and unpause it at 17:25, it only runs the job that was registered to the queue before the pause is triggered (the one that was supposed to run at 17:00). But then it runs the next job at 17:30 and completely ignores the jobs that were supposed to run at 17:10 and 17:20.

I guess this behavior is fine for most cases but in my case jobs collect some data based on a time range and scheduled time. For example, if a job is scheduled to 17:00, it collects data created between 16:50-17:00. So I want to be able to re-run all the missed jobs while the queue is paused.

I appreciate any insights or suggestions on how to handle this situation effectively. Thank you!


Solution

  • It turns out there is no solution for this use case in BullJS. Each repeatable job creates the job that is supposed to run after that. And once the queue is paused no job is added to the queue. When the queue is unpaused again, the delayed job runs and creates only the next job for the current time.