Browse Source

定时任务

release_0.0.2
巴林闲侠 3 years ago
parent
commit
89749c7dc2
  1. 2
      code/VideoAccess-VCMP/api/app/lib/index.js
  2. 45
      code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js
  3. 2
      code/VideoAccess-VCMP/api/app/lib/schedule/index.js
  4. 1
      code/VideoAccess-VCMP/api/package.json

2
code/VideoAccess-VCMP/api/app/lib/index.js

@ -30,7 +30,7 @@ module.exports.entry = function (app, router, opts) {
utils(app, opts) utils(app, opts)
// 定时任务 // 定时任务
// schedule(app, opts) schedule(app, opts)
// 鉴权中间件 // 鉴权中间件
router.use(authenticator(app, opts)); router.use(authenticator(app, opts));

45
code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js

@ -3,16 +3,43 @@ const moment = require('moment')
module.exports = function (app, opts) { module.exports = function (app, opts) {
const freshYingshiState = schedule.scheduleJob( const freshYingshiState = schedule.scheduleJob(
'* * 4 * * *', // '* * 4 * * *',
// '* */1 * * * *', '*/8 * * * * *',
async () => { async () => {
try { try {
const { models } = app.fs.dc // const { models } = app.fs.dc
await models.UserToken.destroy({ // const { varifyYingshiBelongSecretBySerialNo, token4yingshi } = app.fs.utils
where: { // const secretRes = await models.SecretYingshi.findAll()
expired: { $lt: now } // for (let s of secretRes) {
} // const tokenYingshi = await token4yingshi(s.dataValues)
}) // // 查询所有设备
// let pageStart = 0
// let deviceList = []
// while (pageStart >= 0) {
// const deviceRes = await app.fs.yingshiRequest.post('lapp/device/list', {
// query: {
// accessToken: tokenYingshi,
// pageStart,
// pageSize: 50
// }
// })
// if (deviceRes.code == 200) {
// if (deviceRes.data.length) {
// deviceList = deviceList.concat.apply(deviceList, deviceRes.data)
// pageStart++
// } else {
// pageStart = -1
// }
// }
// }
// console.log(deviceList);
// }
// const await models.UserToken.destroy({
// where: {
// expired: { $lt: now }
// }
// })
} catch (error) { } catch (error) {
app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`);
@ -20,6 +47,6 @@ module.exports = function (app, opts) {
}); });
return { return {
freshYingshiState // freshYingshiState
} }
} }

2
code/VideoAccess-VCMP/api/app/lib/schedule/index.js

@ -9,7 +9,7 @@ module.exports = async function (app, opts) {
for (let k of Object.keys(schedule)) { for (let k of Object.keys(schedule)) {
console.info(`定时任务 ${k} 启动`); console.info(`定时任务 ${k} 启动`);
} }
app.fs.utils = { app.fs.schedule = {
...app.fs.schedule, ...app.fs.schedule,
...schedule, ...schedule,
} }

1
code/VideoAccess-VCMP/api/package.json

@ -24,6 +24,7 @@
"koa-proxy": "^0.9.0", "koa-proxy": "^0.9.0",
"moment": "^2.24.0", "moment": "^2.24.0",
"mqtt": "^4.3.7", "mqtt": "^4.3.7",
"node-schedule": "^2.1.0",
"path": "^0.12.7", "path": "^0.12.7",
"path-to-regexp": "^3.0.0", "path-to-regexp": "^3.0.0",
"pg": "^7.9.0", "pg": "^7.9.0",

Loading…
Cancel
Save