node-cron
node-cron copied to clipboard
Pass job instance as onTick callback parameter
Actually we can't manipulate the job from it's callback.
It would be really cool to be able to pause it and update it depending the task itself.
For this use case the simplest way is to pass the CronJob instance as parameter for onTick and onComplete.
Here's a small use case:
const exec = async (job: CronJob) => {
job.stop()
// Do the job...
job.start()
}
new CronJob('* * * * * *', exec, () => {}, true)
Cant you do this by just passing in the instance like this?
var runCron = async function (job: CronJob) {
console.log("CRON running", job.running)
}
var cronJob = new CronJob({
cronTime: '0 */5 * * * *',
onTick: () => runCron(cronJob),
start: true
})