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.
39 lines
1.1 KiB
39 lines
1.1 KiB
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: false,
|
|
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;
|
|
}
|