You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
811 B
29 lines
811 B
const moment = require('moment')
|
|
const { handleTask } = require('./taskHandle');
|
|
|
|
//根据任务配置生成定时任务
|
|
module.exports = async function (app, task) {
|
|
|
|
let job = null
|
|
try {
|
|
job = app.fs.scheduleInit(
|
|
{
|
|
interval: task.cron,
|
|
immediate: true,
|
|
proRun: false,
|
|
},
|
|
async () => {
|
|
try {
|
|
await handleTask(app, task);
|
|
console.log(task.taskName, moment().format('YYYY-MM-DD HH:mm:ss'));
|
|
} catch (error) {
|
|
app.fs.logger.error(`sechedule: taskJobs, error: ${error}`)
|
|
}
|
|
});
|
|
|
|
} catch (error) {
|
|
app.fs.logger.error(`sechedule: taskJobs, error: ${error}`);
|
|
}
|
|
|
|
return job;
|
|
}
|