简体   繁体   中英

node-schedule should run every 1 hour in node js

I have created crone job for every minute

import * as schedule from "node-schedule"

schedule.scheduleJob('* * * * *', async () => {
            console.log("running every minute")
        });

the above working perfectly for every minute. similarly I have task which has to execute for every hour. I tried like below

schedule.scheduleJob('0 0 */1 * *', async () => {
            console.log("running every minute")
        });

But unfortunately its not working every hour as expected. Is there any thing I'm missing

i think you want "0 */1 * * *". Also you can use this great website to make sure your crontab is correct: https://crontab.guru/

based on node-schedule the third * is hour

*    *    *    *    *    *
┬    ┬    ┬    ┬    ┬    ┬
│    │    │    │    │    │
│    │    │    │    │    └ 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)

for every one hour just try

schedule.scheduleJob('0 0 */1 * * *', async () => {
        console.log("running every minute")
 });

For every Hour it should be:

schedule.scheduleJob('0 0 */1 * * *', async () => {
     console.log("running every hour")
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM