0

I have checked on node-schedule

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

I have done the same to run at Every 9AM but it runs more than once per day.

let tenSecCron = schedule.scheduleJob('0 0 9 * * *', async () => {
    this.runJobs();
});
Charlie
  • 22,886
  • 11
  • 59
  • 90
Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71

2 Answers2

3

Another approach is to use object literal syntax as follows:

var j = schedule.scheduleJob({hour: 9, minute: 0} , async () => {
    this.runJobs();
});

Beside this, it should be noted node-schedule is an in-memory scheduler and as such it is not based on cron. As a consequence scheduling will only work as long as the node.js process is running. If it is restarted you may experience strange effects like your jobs get scheduled right away.

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
Marcus
  • 1,097
  • 11
  • 21
1

I believe the correct cron expression is this:

0   0   9   ?   *   *   * 

If your scheduler defies the above expression, later.js is a good library for accurate results.

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • As a variation `'0 0 9 1-31 * * * '` should also work. However, the schedule `'0 0 9 * * *'` trialled by the OP should also work given that hour schedule is 24 hours as documented. – Marcus Mar 29 '19 at 09:13