介紹
node-schedule贮喧,npm上 下載量 賊nb的定時(shí)任務(wù)包乡革,它可以幫你在指定時(shí)間段執(zhí)行你的腳本
核心代碼-定時(shí)任務(wù)
const schedule = require('node-schedule')
// 指定多個(gè)規(guī)則
// 推薦使用 `Recurrence Rule Scheduling` 風(fēng)格,便于理解
const Rule1 = new schedule.RecurrenceRule()
const Rule2 = new schedule.RecurrenceRule()
// Rule1 是每小時(shí)的 10分/33分/50分執(zhí)行
Rule1.minute = [10, 33, 50]
// Rule2 是每天10點(diǎn)/14點(diǎn)/20點(diǎn)的01分/10分/30分 執(zhí)行
Rule2.hour = [10, 14,20]
Rule1.minute = [1, 10, 30]
// 一個(gè)規(guī)則支持多個(gè)條件 可以設(shè)置
// Rule1.second 秒
// Rule1.minute 分
// Rule1.hour 小時(shí)
// Rule1.date 日期
// Rule1.month 月份
// Rule1.year 年份
// Rule1.dayOfWeek 每周幾
schedule.scheduleJob(Rule1, function () {
// 每小時(shí)的 10分/33分/50分執(zhí)行
console.log('Rule1')
})
schedule.scheduleJob(Rule2, function () {
// 每天10點(diǎn)/14點(diǎn)/20點(diǎn)的01分/10分/30分 執(zhí)行
console.log('Rule2')
})