0

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

change need
  • 137
  • 2
  • 6
  • 23

4 Answers4

0

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

Muhammad Raza
  • 41
  • 1
  • 6
0

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")
 });
Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39
0

You should wirte the cron string completely with length of 6 like "0 0 */1 * * *", because it is parsed backwards by schedule.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 24 '23 at 22:52
-1

For every Hour it should be :

schedule.scheduleJob('0 0 */1 * * *', async () => {
     console.log("running every hour")
 });
Md Nazmul Hossain
  • 2,768
  • 5
  • 26
  • 49