Skip to content
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

Some jobs will be skipped in some cases #315

Open
Tracked by #674
zexee opened this issue Nov 8, 2017 · 18 comments
Open
Tracked by #674

Some jobs will be skipped in some cases #315

zexee opened this issue Nov 8, 2017 · 18 comments
Labels
type:bug Bug reports and bug fixes

Comments

@zexee
Copy link

zexee commented Nov 8, 2017

In my case, if multiple jobs are scheduled at the exactly the same time, some might be skipped. By looking at the code, I see that each task has a 1000-millisecond interval callback all the times, and at each call, if the current time matches, the job runs. Sometimes, when multiple jobs are called at the same second, and plus slow CPU or heavy task or slow nodejs or the callback happens to be at the very end of that second, some of them might skipped the second 0 (if the second is not set, it will default to 0) and they will not run. In other words, this mechanism is very unreliable.

I don't see any quick fix for this. I think the best way is the node-scheduler way, which calculate the next running time for each task and set only one callback (instead of call every second which consumes CPU).

If you are using this for serious jobs like the cron replacement in a server, I highly recommend you to switch another lib. I think the author should state this in the README since it might cause serious problems and hard to find out why.

@zexee zexee changed the title Job sometime will be skipped Some jobs will be skipped in some cases Nov 9, 2017
@ncb000gt
Copy link
Member

It's been a while, but I believe that we had originally written the code the way you are suggesting here. There were some issues with it and so it got reworked along with a bunch of other code in the process. I'm happy to revisit this mechanism at some point because I agree that it should be more reliable than what you are describing.

I'll keep the ticket open for the rare chance I get time and can work on it or so that someone else can jump in and pr it.

@sshahar1
Copy link

In my opinion, this should be at least documented. I was checking why some of my cron jobs don't start, and accidentally bumped into this discussion.

@vatsal2210
Copy link

I have the same issue. I added more than 20 schedule in some cases it execute and others not.

@MarkusPint
Copy link

Same here, I have 7 jobs and randomly some jobs are sometimes skipped

@majidhassan
Copy link

Any updates on this issue? I'm comparing between cron, node-schedule, agenda and bull. Should I drop cron because of this issue?

@kbbgl
Copy link

kbbgl commented Oct 2, 2018

One weird behavior I noticed is that for some reason, when the I run the following pattern:

'0 00 6 * * *' - and print out the next interval that the job will be run, it skips a week:

let nextSend = jobsCollection[this._id].cronJob.cronTime.sendAt();
let expiration = nextSend - new Date()

logger.info('execute job ${this.jobType} next run will be at: ${nextSend.toString()});
jobsBroker.executeJob(this, expiration)

Output:
[job: 5ba8d193603baf0a9c8ba899 type: dashboardSubscription scheduleString: 0 00 6 * * * next run will be at: **Mon Sep 24 2018 06:00:00 GMT-0600]**

[job: 5ba8d193603baf0a9c8ba899 type: dashboardSubscription scheduleString: 0 00 6 * * * next run will be at: **Mon Oct 01 2018 06:00:00 GMT-0600]**

@jodevsa
Copy link
Collaborator

jodevsa commented Oct 6, 2018

@kbbgl are you using a specific timezone with that cron string?

@kbbgl
Copy link

kbbgl commented Oct 6, 2018

@jodevsa it's variable, dependent on the timezone of the client.

@jodevsa
Copy link
Collaborator

jodevsa commented Oct 6, 2018

@kbbgl It would really help in figuring out what exactly is happening.

I'm getting the following output from running this :

const CronTime = require('./cron').CronTime;
var cronTime = new CronTime('0 00 6 * * *');
var nextDate = cronTime.sendAt();

output:
moment("2018-10-07T06:00:00.000")

@ncb000gt
Copy link
Member

Is anyone still seeing this issue? We've since pushed a couple changes up to v1.5.0. Please review on that version. This sounds similar to GH-385, but I'm not certain at the moment and am having a hard time reproducing the code in there.

Let us know, thanks.

@codypace68
Copy link

I'm still having this issue.

@ncb000gt
Copy link
Member

ncb000gt commented Feb 16, 2019

@codypace68 which version of the module, node, and so forth? Also, can you share the cron syntax and a example of how you're using it?

@cedric-vinexplore
Copy link

We have the same issue with v8.15.0 of nodejs and v1.5.0 of the lib. It is hard to reproduce I think. It seems to skip launch when the date is over (for example because an IO use the process at the time when the cron have to valid).

@MichaelLiss
Copy link

I am missing a job once in a while as well.

@DigitalLeaves
Copy link

Had the same problem. There seems to be an issue if you start several jobs "simultaneously" (in a short period of time). In my case, I had to switch to node-cron, who works well in that scenario.

@VitorBrangioni
Copy link

Same issue, I going to node-schedule :(

@1valdis
Copy link

1valdis commented Jul 24, 2020

Any updates on that? It's been a while..

@intcreator
Copy link
Collaborator

the callback intervals should be longer than 1 second, I believe they are as long as the full time between executions unless the execution time is more than a month away. if anyone is still having this issue could you make a test case for it following the conventions here? https://github.com/kelektiv/node-cron/blob/master/tests/cron.test.js

@sheerlox sheerlox added the type:bug Bug reports and bug fixes label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug reports and bug fixes
Projects
None yet
Development

No branches or pull requests