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!---------------------------');
});
Make a new line at the bottom of this file and insert the following code. Of course, replace our example script with the command or script you wish to execute, but keep the */5 * * * * part as that is what tells cron to execute our job every 5 minutes.
“At every 5th minute.” Cron job every 5 minutes is a commonly used cron schedule. We created Cronitor because cron itself can't alert you if your jobs fail or never start. Cronitor is easy to integrate and provides you with instant alerts when things go wrong.
How does it work? The asterisk (*) operator specifies all possible values for a field. For example, an asterisk in the hour time field would be equivalent to every hour or an asterisk in the month field would be equivalent to every month. An asterisk in the every field means run given command/script every minute.
If you need to repeat a task on a schedule, you can use the cron service. The cron service is a time based job scheduling system that starts when the system boots. Every minute the cron service checks whether any scheduled jobs to run, and if so, it runs them.
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!---------------------------');
});
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With