Job still fired after .cancel()
See original GitHub issueHello there,
We’re having a weird issue with node-schedule. When having a lot of jobs firing at the same time (a lot = more than 20) and deleting another job one day after it was created, this job is still fired on its due time, every day.
Here’s our process: We have three kinds of jobs, and we’re saving each of them in an array.
this.scheduler = {
true: [],
false: [],
later: []
};
After initializing this array, we process our recurrence rule which is a bit too complicated to show here. If we don’t do anything after that, the reccurrence rule works fine and jobs are fired whenever they’re supposed to.
The issue happens after we’ve deleted the job (if we delete it one day or more after its creation).
Here’s the way we’re deleting our jobs:
deleteScheduledJobs = function() {
for (let laterJob of this.scheduler.later) {
if (laterJob != null) {
laterJob.cancel();
}
}
for (let trueJob of this.scheduler.true) {
if (trueJob != null) {
trueJob.cancel();
}
}
for (let falseJob of this.scheduler.false) {
if (falseJob != null) {
falseJob.cancel();
}
}
this.scheduler = {
true: [],
false: [],
later: []
};
When looping on schedule.scheduleJobs
and listing pending invokations before canceling, we have this:
JOB=<Anonymous Job 97> - PENDING INVOCATIONS=[{"fireDate":"2017-05-31T08:00:00.446Z","recurrenceRule":{"recurs":true,"year":null,"month":null,"date":null,"dayOfWeek":null,"hour":10,"minute":0,"second":0}}]
JOB=<Anonymous Job 98> - PENDING INVOCATIONS=[{"fireDate":"2017-05-31T08:10:00.447Z","recurrenceRule":{"recurs":true,"year":null,"month":null,"date":null,"dayOfWeek":null,"hour":10,"minute":10,"second":0}}]
After canceling those jobs, they don’t appear in schedule.scheduledJobs
and when doing something like myJob.pendingInvocations()
the result is empty. As it should be. However, the job is still fired at the correct time even though it’s been cancelled. And we know it’s been fired because the callback is fired.
We have absolutely no idea of where the issue is coming from or what we may have done wrong. It seems wer’e canceling jobs properly.
Is there any kind of stress issue on node-schedule that we’re not aware of? Is there any way to see what could be firing our callback if not the jobs?
Thank you, we’ll appreciate any kind of help!
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (5 by maintainers)
I have this issue too, but I don’t have any clue about why this happens either.
after job canceled, the job has deleted in
scheduledJobs
, but still fires.The issue happened with canceling jobs that are delayed and scheduled with setImmediate(), which didn’t set timerID to the pending invocation.
In our case we want to cancel any pending invocations no matter if it’s scheduled to happen in future or should happen in the past but delayed due to other jobs. So our fix is simply replacing the setImmediate() with setTimeout(…, 0) and return a timerID anyways. (we could use “return setImmediate(…)” and call clearImmediate() in cancel() function, please let me know if you want me to change it to this way).
A PR was created at: https://github.com/node-schedule/node-schedule/pull/379