'how to stop schedule on cron using node.js
Im using node-schedule and if user type !stopTime the cron will be stop... but in my codes, its not working well here's my code:
if (input.toLowerCase() == "!starttime") {
console.log("Time will be run for" + "every minutes!");
var taskTime = cron.schedule('*/1* * * *', () => {
let time = new Date().toLocaleString('en-US', {timeZone: 'Asia/Manila'}).split(",");
console.log("🕛Time Check: \n" + time[1] + "\n\Timezone: Asia/Manila");
}, {
scheduled: false
});
taskTime.start();
}
if (input.toLowerCase() == "!stoptime") {
console.log("Time has been stopped successfully!");
var taskTime = cron.schedule('*/1 * * * *', () => {
console.log("Time Check For Every Minutes Has Been Stop!");
});
taskTime.stop();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|