node-cronjob 中的时间模式
time pattern in node-cronjob
我正在使用 node-cron。请帮我解释一下它们之间的区别:
var pattern_1 = '58 * * * * *';
var pattern_2 = '*/58 * * * * *';
当运行这个函数时:
new CronJob(pattern, function() {
console.log('lalalalala')
}, null, true, 'America/Los_Angeles');
如cron man page所述:
Step values can be used in conjunction with ranges. Following a range
with ''/'' specifies skips of the number's value through the
range.
和:
Steps are also permitted after an asterisk, so if you want
to say ''every two hours'', just use ``*/2''.
所以:
var pattern_1 = '58 * * * * *';
执行"at 58th seconds of every minute"。第二个模式:
var pattern_2 = '*/58 * * * * *';
执行"every 58 seconds".
第一个模式将 运行 您的 cronjob 每 58 秒:00:00:58、00:01:58、00:02:58...等等。
斜杠字符可用于标识周期值。例如 */15 * * * * *
表示,您的工作将 运行 每 15 秒:00:00:15、00:00:30、00:00:45 ...等等。
在我看来 */58
看起来不是很有用。这将在每分钟的第 58 秒执行一次,因此只需使用第一个。
第二种模式:
var pattern_1 = '58 * * * * *';
它在“每分钟的第 58 秒”执行。
第二种模式:
var pattern_2 = '*/58 * * * * *';
与模式 1 相同,因此它也在“每分钟的第 58 秒”执行。
我正在使用 node-cron。请帮我解释一下它们之间的区别:
var pattern_1 = '58 * * * * *';
var pattern_2 = '*/58 * * * * *';
当运行这个函数时:
new CronJob(pattern, function() {
console.log('lalalalala')
}, null, true, 'America/Los_Angeles');
如cron man page所述:
Step values can be used in conjunction with ranges. Following a range with ''/'' specifies skips of the number's value through the range.
和:
Steps are also permitted after an asterisk, so if you want to say ''every two hours'', just use ``*/2''.
所以:
var pattern_1 = '58 * * * * *';
执行"at 58th seconds of every minute"。第二个模式:
var pattern_2 = '*/58 * * * * *';
执行"every 58 seconds".
第一个模式将 运行 您的 cronjob 每 58 秒:00:00:58、00:01:58、00:02:58...等等。
斜杠字符可用于标识周期值。例如 */15 * * * * *
表示,您的工作将 运行 每 15 秒:00:00:15、00:00:30、00:00:45 ...等等。
在我看来 */58
看起来不是很有用。这将在每分钟的第 58 秒执行一次,因此只需使用第一个。
第二种模式:
var pattern_1 = '58 * * * * *';
它在“每分钟的第 58 秒”执行。
第二种模式:
var pattern_2 = '*/58 * * * * *';
与模式 1 相同,因此它也在“每分钟的第 58 秒”执行。