Reputation: 3920
I'm using the following job scheduler
code to print Today is recognized by Rebecca Black!-
every day at 12AM.
// executes every day at 12:AM
var rule = new schedule.RecurrenceRule();
rule.dayOfWeek = [0, new schedule.Range(1, 6)];
rule.hour = 15;
rule.minute = 14;
schedule.scheduleJob(rule, function() {
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
How can I print for every 5
minutes
I used the following way but it is not working...
var rule = new schedule.RecurrenceRule();
rule.minute = 5;
schedule.scheduleJob(rule, function() {
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
Upvotes: 21
Views: 57205
Reputation: 5442
You can use the cron format:
var event = schedule.scheduleJob("*/5 * * * *", function() {
console.log('This runs every 5 minutes');
});
The cron format consists of:
* * * * * *
┬ ┬ ┬ ┬ ┬ ┬
│ │ │ │ │ |
│ │ │ │ │ └ 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)
Upvotes: 29
Reputation: 673
Simple and good examples are given on http://www.codexpedia.com/javascript/nodejs-cron-schedule-examples/
Upvotes: 3
Reputation: 11244
var rule = new schedule.RecurrenceRule();
rule.minute = new schedule.Range(0, 59, 5);
schedule.scheduleJob(rule, function(){
console.log(rule);
console.log('Today is recognized by Rebecca Black!---------------------------');
});
Upvotes: 37