npm-cron started from inside a function. But can't stop like, from inside a function. the running continues for infinity.
I have to run it in a certain condition until another condition is met. Whenever another condition is happening, I have to stop running.
And also restart the process from somewhere else.
The start is done. Cron Stop is not working.
const { log } = require('console');
const cron = require('node-cron');
let i = 0;
console.log("Hello World");
const task = cron.schedule('* * * * * *', () => {
_find();
task.stop();
console.log('running a task every 1 second');
},{
scheduled: false
});;
function _find() {
i++;
console.log(i);
_checking(i);
}
function _checking(i) {
if(i===0){
console.log('started')
task.start();
}
else if (i > 3) {
console.log('yes');
task.stop();
console.log('stopped');
} else {
console.log('no');
}
}
_checking(i);