I've created a cron-job to run a task and I want it to stop at some specific condition inside the scheduler, but it is not working.
How can I stop cron job inside the scheduler?
Here is my code:
// cron-job.js
const cron = require('node-cron');
const scheduler = cron.schedule('* * * * *', () => {
let result = fetchResultAfterSomeOperation();
if (result < 20) {
scheduler.stop(); //------------------------ It doesn't work
}
}, {
scheduled: false
});
scheduler.start();