Cronjobs getting called multiple times
See original GitHub issueI’m submitting a…
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I am using NestJs and trying to use the schedule module for cronjobs. One of the methods is decorated with @Cron('*/30 * * * * * ') and I expected it to run only once after 30 seconds. The issue is after every 30 seconds, the cron runs three times. This is a consistent behavior and happens all the time. However I have observed that other methods which are also cronjobs are working as expected(run only once). Have been trying to figure out the root cause but there is no luck so far.
Expected behavior
The cronjobs should always only run only once.
Minimal reproduction of the problem with instructions
@Cron('*/10 * * * * *')
async triggerSessionRemindersCron(): Promise<void> {
LoggerService.logger.info(`Date:: ${new Date().getTime()}`);
LoggerService.logger.info('CronjobService::triggerSessionReminders BEGIN');
// await this.triggerEventsForSessionReminders().catch((e) => {
// LoggerService.logger.error(e);
// });
}
What is the motivation / use case for changing the behavior?
The current implementation for me results in sending multiple events to webengage which in turn sends multiple notifications to the users.
Environment
Nest version: 7.5.4
For Tooling issues:
- Node version: 12.18.2 -->
- Platform: Mac
Others:
Using npm version 6.14.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Script was triggered multiple times by cron - Blog
I am using crontab to trigger a PHP-scraping script on regular basis, but the script gets called multiple times. A recherché revealed that...
Read more >How can I prevent Cronjobs from running multiple times?
It is common to execute cronjobs frequently, for example, every minute. The execution time, in tendency, increases with a growing data set.
Read more >Cron job being called multiple times : r/node - Reddit
We are looping through the clinic and have been trying to send emails at 9am based on the clinic timezone. In our case...
Read more >Cronjob executing multiple times at once - Server Fault
The python script is simply outputting the current time so we can say for sure that its cronjob which is opening the python...
Read more >Why do some cron jobs execute the same task multiple times ...
The cron daemon reads your crontab and uses that to plan to run the jobs. If all the times are identical it will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FYI: I found that adding a
name
fixed my duplicates=>
The order of the log entries makes it a bit confusing, but if you look at the time stamps you can see it calls
Test named
once every 10 seconds butTest unnamed
twice every 10 secondsAlso it seems to be that if this is an underlying issue in https://github.com/kelektiv/node-cron then this won’t be fixed quite soon since the project isn’t really maintained anymore. See here https://github.com/kelektiv/node-cron/issues/578