const moment = require('moment') const { handleTask } = require('./taskHandle'); //根据任务配置生成定时任务 module.exports = async function (app, task) { let job = null const { models } = app.fs.dc const startTime = moment() try { job = app.fs.scheduleInit( { interval: task.cron, immediate: true, proRun: false, }, async () => { try { await handleTask(app, task); } catch (error) { app.fs.logger.error(`sechedule: taskJobs, error: ${error}`) } }); } catch (error) { const endTime = moment() const logBody = { task: task.id, success: true, details: '采集失败' + JSON.stringify(error).substring(0, 248), startTime: startTime, endTime: endTime } await models.AcquisitionLog.create(logBody) app.fs.logger.error(`sechedule: taskJobs, error: ${error}`); } return job; }