Ive got an array of cron jobs in my project which trigger at different times. I want to ability to stop all of these jobs when an event is triggered and for them not to start again until also manually triggered.
My issue is, i can stop my jobs, but then they appear to start themselves back up again..
Ive confirmed this by adding an addition cron which just checks the status regularly. Initially, the status is 'scheduled', then when i trigger to stop the status changes to 'stoped' which is correct, and then after sometime each one will eventually update its status to 'scheduled' again. Whats doing this? Is there another way I can disable these jobs so they stay stopped until ive manually started them?
const cron = require('node-cron');
jobs.push(cron.schedule('5 1 * * 1,4', () => {
func.runOne();
}));
jobs.push(cron.schedule('0 1 * * *', () => {
func.runTwo();
}));
jobs.push(cron.schedule('0 2 * * *', () => {
func.runThree();
}));
jobs.push(cron.schedule('30 2 * * *', () => {
func.runFour();
}));
cron.schedule('*/10 * * * * *', () => {
console.log(`checking the status of jobs for task`);
jobs.forEach((job) => {
console.log(`Job status is: ${job.getStatus()}`);
});
});
exports.stopJobs = () => {
jobs.forEach((job) => {
job.stop();
});
};