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

When scheduled to run once a minute and recoverMissedExecutions is on, it runs again the next second. #400

Open
adamk33n3r opened this issue Mar 26, 2023 · 3 comments

Comments

@adamk33n3r
Copy link

adamk33n3r commented Mar 26, 2023

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
@gronel
Copy link

gronel commented May 26, 2023

same issue , I also set cron.stop() but it did not work

@Hexagon
Copy link

Hexagon commented Jun 3, 2023

Try https://github.com/hexagon/croner instead

@tamilselvan-elangovan
Copy link

Hello Adam, I had fixed the issue and it has some merge issue. Let me know if the updated code helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants