peng.peng
2 years ago
8 changed files with 124 additions and 40 deletions
@ -0,0 +1,28 @@ |
|||
const moment = require('moment') |
|||
// let TEST = false
|
|||
TEST = true |
|||
|
|||
module.exports = async function (app, task) { |
|||
|
|||
let job = null |
|||
try { |
|||
job = app.fs.scheduleInit( |
|||
{ |
|||
interval: task.cron, |
|||
immediate: TEST, |
|||
proRun: !TEST, |
|||
}, |
|||
async () => { |
|||
try { |
|||
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; |
|||
} |
@ -0,0 +1,41 @@ |
|||
const moment = require('moment') |
|||
const rimraf = require('rimraf'); |
|||
const fs = require("fs"); |
|||
const path = require("path") |
|||
|
|||
let TEST = false |
|||
// TEST = true
|
|||
|
|||
module.exports = async function (app, opts) { |
|||
|
|||
const jobs = {} |
|||
try { |
|||
const { models } = app.fs.dc |
|||
const tasks = await models.AcquisitionTask.findAll({ |
|||
where: { |
|||
enabled: true |
|||
} |
|||
}) |
|||
tasks.map(s => { |
|||
const job = app.fs.scheduleInit( |
|||
{ |
|||
interval: s.cron, |
|||
immediate: TEST, |
|||
proRun: !TEST, |
|||
}, |
|||
async () => { |
|||
try { |
|||
console.log(s.taskName, moment().format('YYYY-MM-DD HH:mm:ss')); |
|||
} catch (error) { |
|||
app.fs.logger.error(`sechedule: taskJobs, error: ${error}`) |
|||
} |
|||
}); |
|||
jobs[s.id] = job; |
|||
}) |
|||
|
|||
} catch (error) { |
|||
app.fs.logger.error(`sechedule: acqTask, error: ${error}`); |
|||
} |
|||
|
|||
return { taskJobs: jobs } |
|||
} |
Loading…
Reference in new issue