BullMQ uses a queue scheduler to manage the delayed jobs. The queue scheduler is a separate process that maintains the correct state of delayed jobs, moving them from the
delayed set to the
waiting list when they are due.
You can initiate a queue scheduler like this:
In the above code,
'myQueue' is the name of your queue. The queue scheduler will ensure that all jobs in
myQueue with a delay are moved to be processed when their time comes.
However, note that creating a
QueueScheduler instance will also automatically create a Redis connection, so you need to ensure your environment can handle this load.
The queue scheduler is also responsible for maintaining job deadlines and removing stalled jobs.
Please also remember to properly close queue schedulers when they are not needed anymore, preferably using an async exit handler. Here is an example:
In this way, BullMQ queue scheduler helps efficiently managing the job queue, ensuring jobs run at their specified times, and keeping the queue clean.