-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
option to wait for job completion before executing the next one #556
Comments
For anyone interested, here's the work-around that I used private async fireTick() {
if(this.isRunning) {
this.logger.info('This CRON is already in execution');
return;
}
this.isRunning = true;
try {
// Call your onTick callback here
await this.myOnTickCallback();
} catch(exception) {
this.logger.error('Tick stopped due to an error');
this.logger.error(exception);
}
this.isRunning = false;
} And here is how I would start this CRON public start() {
const intervalString = `*/5 * * * * *`;
const options: CronJobParameters = {
cronTime: intervalString,
onTick: () => this.fireTick(),
runOnInit: true,
};
this.cronJob = new CronJob(options);
this.cronJob.start();
} Note: |
That is exactly how I do it, but I eventually run into a situation where the job stops completely because In any case it would be great if there were a solution for this directly on the library both for preventing code repetition with this whole structure on every job and to natively prevent conflicts. |
feel free to make a PR! I'm pretty busy so it might be a while before I get to this one |
drawing inspiration from
|
hmm that croner link isn't working for me @sheerlox 😕 is the idea that we store the tick of the last execution to compare it with something? otherwise we can just store the boolean of whether the job is still running. also we have |
@intcreator link updated with GitHub blob permalink |
|
oh so in the case that ticks take different times, maybe a tick other than the one from |
Note: I quickly checked how EDIT: |
@intcreator yeah, I was correct... opened an issue: #710 |
ok sounds good also it's unfortunate that internally it's called |
from docs: "
wdyt? |
yep, sounds good to me |
blocked by #711. once merged this is ready for implementation :) |
related to #713 since both features need to watch for callbacks completion |
i put my 2 cents here sharing my own workaround
usage
full demo snippet
|
Great workaround @konradkevin, thanks for sharing! |
This can be useful in cases where two ticks running at the same time could lead to conflicts, and while it's not supposed to happen, maybe some undetected errors/bugs in the
onTick
call might lead to one tick being too slow and having multiple ticks running at the same timeConsidering you already have thejob.running
boolean, I think it could be a great addition whilst not being too hard, to add a new parameter that could prevent the job to fire a new tick, if one is already running.I gave a look at the code, and figured that I misunderstood how
running
was working: It determines whether the job is running, not if one tick is running. Regardless of that, I still think this could be a nice feature, though I see that it is harder to implement nowRelated
The text was updated successfully, but these errors were encountered: