Squiss.stop: Wait for currently running jobs to complete
My comprehension of the stop method is that it tells Squiss to stop polling/fetching new jobs, but it does nothing about currently running jobs.
To properly handle a graceful shutdown when the server stops (on SIGTERM signal), I think that the stop method should also accept a timeout param in ms and returns a Promise after all the running jobs are completed (or the timeout has expired). This way, we could have the following code:
// Handling graceful shutdown
const gracefulShutdown = () =>
myQueue.stop(true, 10000)
.then(() => process.exit(0));
process.on('SIGTERM', gracefulShutdown);
Jobs which are in the middle of their processing now have 10 additional seconds, to either complete their job, rollback some transactions, etc What do you think?
Any update?
@loris I have created an enhanced, typescriped library based on this one with your fix in it - https://github.com/PruvoNet/squiss-ts Please be aware that the api is not fully backwards compatible. Please let me know if that helps you