node-cron
node-cron copied to clipboard
Cron not stop
Hi, I am trying to stop a cron but look like it not work
In file myCron.js
const myCron= new CronJob(
"* * * * * *",
async () => {console.log(
"You will see this message every second",
new Date().toGMTString()
);
},
null,
true,
"America/Los_Angeles"
);
export default myCron;
Then in my api file I import myCron from "..."
and call myCron.start() // This work ok
But in other api I tried to call myCron.stop() // Cron still print console.log
I have the same issue with an async process called. I expected that the process would be aborted, but I have the same issue: stop function does not stop async function
Try something like this
const task = cron.schedule('* * * * *', () => { executeAndDestroy() }, { scheduled: true, America/Los_Angeles' })
const executeAndDestroy = async () => { // do something for me task.stop() }