|
@ -5,11 +5,12 @@ const schedule = require('node-schedule') |
|
|
const initJob = require('./initJob'); |
|
|
const initJob = require('./initJob'); |
|
|
//删除数据库源时 同步删除该数据源资源目录树下元数据
|
|
|
//删除数据库源时 同步删除该数据源资源目录树下元数据
|
|
|
//数据源 数据库配置信息不能更改 若需更改则需要删除数据源重新配置
|
|
|
//数据源 数据库配置信息不能更改 若需更改则需要删除数据源重新配置
|
|
|
let i = 0; |
|
|
const taskRetryIndex = {} |
|
|
async function handleTask(app, task) { |
|
|
async function handleTask(app, task) { |
|
|
// const transaction = await app.fs.dc.orm.transaction();
|
|
|
// const transaction = await app.fs.dc.orm.transaction();
|
|
|
const startTime = moment() |
|
|
const startTime = moment() |
|
|
const { models } = app.fs.dc |
|
|
const { models } = app.fs.dc |
|
|
|
|
|
if (!taskRetryIndex[task.id]) taskRetryIndex[task.id] = 0; |
|
|
try { |
|
|
try { |
|
|
const dataSource = await models.DataSource.findOne({ |
|
|
const dataSource = await models.DataSource.findOne({ |
|
|
where: { |
|
|
where: { |
|
@ -154,15 +155,16 @@ async function handleTask(app, task) { |
|
|
details: '采集成功', |
|
|
details: '采集成功', |
|
|
startTime: startTime, |
|
|
startTime: startTime, |
|
|
endTime: endTime |
|
|
endTime: endTime |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
//日志记录
|
|
|
//日志记录
|
|
|
await models.AcquisitionLog.create(logBody) |
|
|
await models.AcquisitionLog.create(logBody) |
|
|
|
|
|
taskRetryIndex[task.id] = 0; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
i++ |
|
|
|
|
|
console.log('===========------------------------------------------------------------' + task.taskName + moment().format('HH:mm:ss')) |
|
|
console.log('===========------------------------------------------------------------' + taskRetryIndex[task.id] + '----' + task.taskName + '------' + moment().format('HH:mm:ss')) |
|
|
|
|
|
|
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
// await transaction.rollback();
|
|
|
// await transaction.rollback();
|
|
|
const endTime = moment() |
|
|
const endTime = moment() |
|
@ -174,8 +176,13 @@ async function handleTask(app, task) { |
|
|
endTime: endTime |
|
|
endTime: endTime |
|
|
} |
|
|
} |
|
|
await models.AcquisitionLog.create(logBody) |
|
|
await models.AcquisitionLog.create(logBody) |
|
|
// if (app.fs.schedule['taskJobs'][task.id]) schedule.cancelJob(app.fs.schedule['taskJobs'][task.id])
|
|
|
taskRetryIndex[task.id]++; |
|
|
console.log('===========------------------------------------------------------------' + i) |
|
|
//处理采集失败重试
|
|
|
|
|
|
if (task.retried && task.retryCount && task.retryTime && taskRetryIndex[task.id] < task.retryCount) { |
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
handleTask(app, task) |
|
|
|
|
|
}, 1000 * 60 * task.retryCount); |
|
|
|
|
|
} |
|
|
app.fs.logger.error(`sechedule: handleTask, error: ${error}`); |
|
|
app.fs.logger.error(`sechedule: handleTask, error: ${error}`); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|