question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Job still fired after .cancel()

See original GitHub issue

Hello 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:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
goto100commented, Jul 27, 2017

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.

0reactions
wux5commented, Sep 1, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting cancelled virtually, losing your job in reality
Celebrities might bounce back after getting cancelled, ...
Read more >
Employee Rights After a Job Termination - FindLaw
Employees terminated by an employer have certain rights. An employee has the right to receive a final paycheck and the option of continuing ......
Read more >
node-schedule undoing cancellation - Stack Overflow
I tried using job.cancel(true) after cancelling it via plain job.cancel() first as the documentation states that that would reschedule the ...
Read more >
Can You Be Terminated After Resigning? | Indeed.com
In this guide, we will discuss whether you can be terminated after resigning along with how to resign properly.
Read more >
12 Things Everyone Should Know About Employment Law
It is illegal for your employer to terminate you : ... When you are terminated or you quit a job, you are entitled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found