node-cron
node-cron copied to clipboard
Some jobs will be skipped in some cases
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.
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.
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.
I have the same issue. I added more than 20 schedule in some cases it execute and others not.
Same here, I have 7 jobs and randomly some jobs are sometimes skipped
Any updates on this issue? I'm comparing between cron, node-schedule, agenda and bull. Should I drop cron because of this issue?
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]**
@kbbgl are you using a specific timezone with that cron string?
@jodevsa it's variable, dependent on the timezone of the client.
@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")
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.
I'm still having this issue.
@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?
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).
I am missing a job once in a while as well.
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.
Same issue, I going to node-schedule :(
Any updates on that? It's been a while..
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
just did a test running 50 cron jobs that each ran every second, no cron jobs were skipped as far as I could tell. going to close this since I could not duplicate it. I'm guessing our general core algorithm hardening has fixed this issue. if anyone has a test case that can duplicate this we can reopen