When scheduled to run once a minute and recoverMissedExecutions is on, it runs again the next second.
adamk33n3r opened this issue · comments
I have it the schedule set to '59 * * * * *'
so that my task runs once a minute. When I have recoverMissedExceutions
on, my task is run on 59 but then it is run again on the next second 00. Here is an example where var
is the variable passed into the job function and actual
is just printing out a new Date()
inside the job.
running job
var: 2023-03-26T07:48:59.571Z
actual: 2023-03-26T07:48:59.571Z
running job
var: 2023-03-26T07:48:59.575Z
actual: 2023-03-26T07:49:00.575Z
You can see that on the next second after my schedule, it runs it again with the previous second. I believe the culprit is this line https://github.com/node-cron/node-cron/blob/master/src/scheduler.js#L29.
It's doing a lastExecution.getTime() < date_tmp.getTime()
which as you can see from my examples is technically true. lastExecutionTime
is prior to "now minus 1 second" (what date_tmp is).
I think there needs to be some adjustment to the logic here. I don't think missedExecutions
should be 1
in this case but it is. It didn't "miss" anything.
Edit: Actually, it looks like this isn't isolated to once a minute. I just tried it with a * * * * * *
and not always, but sometimes it is still running multiple times in the same manner.
running job
var: 2023-03-26T07:55:23.374Z
actual: 2023-03-26T07:55:23.374Z
running job
var: 2023-03-26T07:55:23.376Z
actual: 2023-03-26T07:55:24.376Z
same issue , I also set cron.stop() but it did not work
Try https://github.com/hexagon/croner instead
Hello Adam, I had fixed the issue and it has some merge issue. Let me know if the updated code helps