'use strict'; const fs = require('fs'); const nodeSchedule = require('node-schedule'); const schedule = ({ interval, immediate }, callback) => { const j = nodeSchedule.scheduleJob(interval, callback); if (immediate) { j.run(); } return j; } // 将定时任务汇集未来可根据需要选取操作 module.exports = async function (app, opts) { fs.readdirSync(__dirname).forEach((filename) => { if (!['index.js'].some(f => filename == f)) { const schedule = require(`./${filename}`)(app, opts) for (let k of Object.keys(schedule)) { console.info(`定时任务 ${k} 启动`); } app.fs.schedule = { ...app.fs.schedule, ...schedule, } } }); };