巴林闲侠
3 years ago
5 changed files with 53 additions and 4 deletions
@ -0,0 +1,25 @@ |
|||
const schedule = require('node-schedule'); |
|||
const moment = require('moment') |
|||
|
|||
module.exports = function (app, opts) { |
|||
const freshYingshiState = schedule.scheduleJob( |
|||
'* * 4 * * *', |
|||
// '* */1 * * * *',
|
|||
async () => { |
|||
try { |
|||
const { models } = app.fs.dc |
|||
await models.UserToken.destroy({ |
|||
where: { |
|||
expired: { $lt: now } |
|||
} |
|||
}) |
|||
|
|||
} catch (error) { |
|||
app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); |
|||
} |
|||
}); |
|||
|
|||
return { |
|||
freshYingshiState |
|||
} |
|||
} |
@ -0,0 +1,18 @@ |
|||
'use strict'; |
|||
|
|||
const fs = require('fs'); |
|||
// 将定时任务汇集未来可根据需要选取操作
|
|||
module.exports = async function (app, opts) { |
|||
fs.readdirSync(__dirname).forEach((filename) => { |
|||
if (!['index.js'].some(f => filename == f)) { |
|||
const schedule = require(`./${filename}`)(app, opts) |
|||
for (let k of Object.keys(schedule)) { |
|||
console.info(`定时任务 ${k} 启动`); |
|||
} |
|||
app.fs.utils = { |
|||
...app.fs.schedule, |
|||
...schedule, |
|||
} |
|||
} |
|||
}); |
|||
}; |
Loading…
Reference in new issue