haifa-reminder/node_modules/cron/examples/long_running_on_tick.js

21 lines
533 B
JavaScript
Raw Normal View History

2023-07-26 11:01:58 +00:00
const CronJob = require('../lib/cron.js').CronJob;
let isRunning = false;
console.log('Before job instantiation');
const job = new CronJob('* * * * * *', function() {
const d = new Date();
console.log('Check every second:', d, ', isRunning: ', isRunning);
if (!isRunning) {
isRunning = true;
setTimeout(function() {
console.log('Long running onTick complete:', new Date());
isRunning = false;
}, 3000);
console.log('setTimeout triggered:', new Date());
}
});
console.log('After job instantiation');
job.start();