kelektiv / node-cron

Cron for NodeJS.
MIT License
8.41k stars 621 forks source link

option to wait for callbacks completion on job.stop() #713

Open YannHulot opened 11 months ago

YannHulot commented 11 months ago

⭐ Suggestion

Do not stop the jobs if the onTick function is being executed. Wait for this function to resolve first and then, resolve job.stop()

💻 Use Cases

Basically I am trying to gracefully shut down my cron jobs when deploying a new version of my back-end.

That means that ideally, I want to call job.stop() on all the ongoing jobs, Then once they are done, I want to close the DB connection and so on and so forth.

The problem is that those jobs are mostly doing async stuff, so if I call a job.stop() and my onTick function is currently running, then, I would like to wait for the onTick function to resolve before the job.stop() function resolves itself so I don't close the DB connection before those jobs are done since they need it.

Related

sheerlox commented 11 months ago

related to #556 since both features need to watch for callbacks completion

rohith1222004 commented 2 days ago

I noticed that PR #894 is linked to this issue for supporting async handling and job status tracking. Is this feature close to completion, or would you still like help working on it?