Reputation: 245
I am not sure if this is even possible.. but I am trying to make it so my cron jobs do NOT run when the server reboots (ie code pushes). I have a cron job running in the very early hours of the day to scrape data which takes ~3 hours. When I do code pushes and my server reboots, the cron jobs run on reboot, causing the data scrape to start again.
This is a node.js based cron job using https://www.npmjs.com/package/cron. After checking docs I couldn't find info on this.
Here is the code I am using to trigger the cron job
new CronJob('0 06 * * *' //run every day at 06:00 AM
,() => {s3Scrape(db);}
,() => {log.debug('!Terminating AWS Job!')}
,true
,'America/Los_Angeles'
,null
,true
);
}
I need this to only run at the specified time and NOT run when the server reboots.
Upvotes: 0
Views: 596
Reputation: 456
it's because you have the setting for "runOnInit" set to true. This will run your cronjobs and fire the onTick event when you first launch the cron jobs. Instead set it to false. This will mean the cronjob will just wait until the time is right to execute.
new CronJob('0 06 * * *' //run every day at 06:00 AM
,() => {s3Scrape(db);}
,() => {log.debug('!Terminating AWS Job!')}
,true
,'America/Los_Angeles'
,null
,false // set this to false
);
}
check out the docs here: https://www.npmjs.com/package/cron
Upvotes: 1