You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi All, first thanks a ton for this. I'm currently using it in a monitoring tool that goes and pulls SQL at set intervals. It seems to be working wonderfully.
I'm trying to prevent these jobs from overlapping and the method is not the most elegant. Right now I'm setting an active parameter to the this object and have an condition to catch if the job is currently executing.
Would it be possible to make something like this built in and is there better way to do it?
Thanks!
var job = new CronJob({
cronTime: '* * * * * *',
onTick: () => {
if (typeof this.isCurrentlyExecuting === 'undefined') {
this.isCurrentlyExecuting = false;
}
if (this.isCurrentlyExecuting) {
console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job already running. Canceling this execution.', this);
return;
}
this.isCurrentlyExecuting = true;
console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job is currently executing');
setTimeout(()=>{
console.log(moment().format('YYYY-MM-DD HH:mm:ss.SS - ') + 'Job is done executing');
this.isCurrentlyExecuting = false;
}, 5000)
},
start: true /* Start the job right now */
});
The code above will output the following:
2017-09-15 18:13:10.38 - Job is currently executing
2017-09-15 18:13:11.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:12.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:13.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:14.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:15.38 - Job is done executing
2017-09-15 18:13:15.38 - Job is currently executing
2017-09-15 18:13:16.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:17.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:18.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:19.38 - Job already running. Canceling this execution. { isCurrentlyExecuting: true }
2017-09-15 18:13:20.38 - Job is done executing
The text was updated successfully, but these errors were encountered:
sheerlox
changed the title
Feature Request / review process, active status to know when job is waiting for next tick or currently executing
active status to know when job is waiting for next tick or currently executing
Sep 30, 2023
Hi All, first thanks a ton for this. I'm currently using it in a monitoring tool that goes and pulls SQL at set intervals. It seems to be working wonderfully.
I'm trying to prevent these jobs from overlapping and the method is not the most elegant. Right now I'm setting an active parameter to the
this
object and have an condition to catch if the job is currently executing.Would it be possible to make something like this built in and is there better way to do it?
Thanks!
The code above will output the following:
The text was updated successfully, but these errors were encountered: