I follow the recommendation here and also this thread and I use the following code in order to gracefully shutdown BullMQ
workers in my development environment on Ubuntu
:
const handleTermination = async () => {
log.info(`Gracefully shutting down worker for queue '${name}'.`);
await worker.close();
};
process.on('SIGTERM', handleTermination).on('SIGINT', handleTermination);
However the above code prevents the app from ending. The result in the console is the following for 3 consecutive Ctrl+C
:
^C[2023-04-23T16:15:46.423] [INFO] development - Gracefully shutting down worker for queue 'X'.
[2023-04-23T16:15:46.423] [INFO] development - Gracefully shutting down worker for queue 'Y'.
^C[2023-04-23T16:15:47.075] [INFO] development - Gracefully shutting down worker for queue 'X'.
[2023-04-23T16:15:47.075] [INFO] development - Gracefully shutting down worker for queue 'Y'.
^C[2023-04-23T16:15:47.793] [INFO] development - Gracefully shutting down worker for queue 'X'.
[2023-04-23T16:15:47.793] [INFO] development - Gracefully shutting down worker for queue 'Y'.
Obviously the process is still there forever and can only be finished with kill -9
. Note that there is no pending job.
What I am missing here?
Of course the problem is gone when I use process.exit()
but I understand that this is not the recommended handling.