Graceful shutdown

BullMQ supports graceful shutdowns of workers. This is important so that we can minimize stalled jobs when a worker for some reason must be shutdown. But note that even in the event of a "ungraceful shutdown", the stalled mechanism in BullMQ allows for new workers to pick up stalled jobs and continue working on them.

Prior to BullMQ 2.0, in order for stalled jobs to be picked up by other workers you need to have a QueueScheduler class running in the system.

From BullMQ 2.0 and onwards, the QueueScheduler is not needed anymore, so the information above is only valid for older versions.

In order to perform a shutdown just call the close method:

await worker.close();

The above call will mark the worker as closing so it will not pick up new jobs, and at the same time it will wait for all the current jobs to be processed (or failed). This call will not timeout by itself, so you should make sure that your jobs finalize in a timely manner. If this call fails for some reason or it is not able to complete, the pending jobs will be marked as stalled and processed by other workers (if correct stalled options are configured on the QueueScheduler).

Last updated

Copyright (c) Inc.