Nodejs script runs every 6 hours

I have this script using the npm module node-shedule. I think I run it every 6 hours, but it works for an hour, when the hour is 0.6,12,18. it can only be started once. I could fix this dirty with a bool, but that is not my style.

a cronjob on Linux is also not an option, it needs to run cross-platform

let schedule = require('node-schedule'); 
let j = schedule.scheduleJob('* */6 * * *', function() {
do smt
});
+4
source share
2 answers

This will be done every minute. Change the cron schedule to 0 */6 * * *to run it only when the minute is 0.

+1
source

You need to do:

let schedule = require('node-schedule'); 

let j = nodeSchedule.scheduleJob('0 0 */5 * * *', function() {
  do smt
});

He will work in the second 0 minute 0 every 6 hours. They use this format.

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
β”‚    β”‚    β”‚    β”‚    β”‚    |
β”‚    β”‚    β”‚    β”‚    β”‚    β”” day of week (0 - 7) (0 or 7 is Sun)
β”‚    β”‚    β”‚    β”‚    └───── month (1 - 12)
β”‚    β”‚    β”‚    └────────── day of month (1 - 31)
β”‚    β”‚    └─────────────── hour (0 - 23)
β”‚    └──────────────────── minute (0 - 59)
└───────────────────────── second (0 - 59, optional)
0
source

Source: https://habr.com/ru/post/1695179/


All Articles