question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CronJob executing several times

See original GitHub issue

I am using cron job to run a task at night only one time but the cron is running multiple times due to which my code gets executed several time. How can I stop this.

`var Job = new CronJob({

cronTime: '* * 01 * * *', //Execute at 1 am every day

onTick  : function() {

    co(function*() {

        yield insertToDatabase(); //this is the function that does insert operation

    }).catch(ex => {

        console.log('error')

    });

},
start   : false,

timeZone: 'Asia/Kolkata'

});`

I have placed the job.start() in the index.js file. Can you please help me figure out what I am doing wrong!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
doowbcommented, Sep 14, 2017

This pattern '* * 01 * * *' is saying “at every second from 01:00:00 to 01:59:59 every day”.

I think you just need to use '00' in place of the minute and second fields: ‘00 00 01 * * *’.

1reaction
diptenagilecommented, Oct 17, 2017

I also had the same problem and i notice that server is run on cluster mode. so need to put cronjob in

if(cluster.isMaster){
   // cronjob
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
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 >
Cronjob executing multiple times at once - Server Fault
Anyone know what the problem may be? The python script is simply outputting the current time so we can say for sure that...
Read more >
Cron running job multiple times - Ask Ubuntu
I guess you want to change it to a single value between 0..59. For more information do, "man 5 crontab". Share.
Read more >
Crons executed multiple times. - The UNIX and Linux Forums
Two cron daemons running? The same jobs in two crontab files? When you say "5.8", I assume you mean Solaris. What does /var/cron/log...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found