每5分钟安排一份工作

Psl*_*Psl 14 javascript node.js

我使用以下job scheduler代码Today is recognized by Rebecca Black!-每天上午12点打印.

// 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!---------------------------');
});
Run Code Online (Sandbox Code Playgroud)

我如何打印每5分钟我使用以下方式,但它不工作...

var rule = new schedule.RecurrenceRule();

rule.minute = 5;
schedule.scheduleJob(rule, function() {
console.log(rule);
    console.log('Today is recognized by Rebecca Black!---------------------------');
});
Run Code Online (Sandbox Code Playgroud)

vin*_*ayr 33

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!---------------------------');
});
Run Code Online (Sandbox Code Playgroud)


J.C*_*ras 13

您可以使用cron格式:

var event = schedule.scheduleJob("*/5 * * * *", function() {
        console.log('This runs every 5 minutes');
    });
Run Code Online (Sandbox Code Playgroud)

cron格式包括:

*    *    *    *    *    *
?    ?    ?    ?    ?    ?
?    ?    ?    ?    ?    |
?    ?    ?    ?    ?    ? 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)
Run Code Online (Sandbox Code Playgroud)