node-cron icon indicating copy to clipboard operation
node-cron copied to clipboard

Cron not stop

Open IRediTOTO opened this issue 5 years ago • 2 comments

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

IRediTOTO avatar Jul 18 '20 10:07 IRediTOTO

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

minirom avatar Oct 02 '20 15:10 minirom

Try something like this

const task = cron.schedule('* * * * *', () => { executeAndDestroy() }, { scheduled: true, America/Los_Angeles' })

const executeAndDestroy = async () => { // do something for me task.stop() }

maxmx03 avatar Nov 21 '20 18:11 maxmx03