function scraper() {
// do something here
}
// CronJob runs function every hour at minute 0 second 0
const scraperTimer = new CronJob('0 0 */1 * * *', function () {
// set random delay between 5(min) and 50(max) minutes
const delay = Math.floor(Math.random() * (3e6 - 300000) + 300000);
setTimeout(() => {
scraper();
}, delay);
console.log(`running scraper in ${delay / 60000} minutes`);
});
scraperTimer.Start()
1条答案
按热度按时间z31licg01#
使用Cron和计时器时最好注意范围,内存泄漏可能会发生。