diff --git a/code/VideoAccess-VCMP/api/app/lib/index.js b/code/VideoAccess-VCMP/api/app/lib/index.js index 0f5456d..98d7560 100644 --- a/code/VideoAccess-VCMP/api/app/lib/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/index.js @@ -30,7 +30,7 @@ module.exports.entry = function (app, router, opts) { utils(app, opts) // 定时任务 - // schedule(app, opts) + schedule(app, opts) // 鉴权中间件 router.use(authenticator(app, opts)); diff --git a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js index acdc492..5b5a279 100644 --- a/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js +++ b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js @@ -3,23 +3,50 @@ const moment = require('moment') module.exports = function (app, opts) { const freshYingshiState = schedule.scheduleJob( - '* * 4 * * *', - // '* */1 * * * *', + // '* * 4 * * *', + '*/8 * * * * *', async () => { try { - const { models } = app.fs.dc - await models.UserToken.destroy({ - where: { - expired: { $lt: now } - } - }) - + // const { models } = app.fs.dc + // const { varifyYingshiBelongSecretBySerialNo, token4yingshi } = app.fs.utils + // const secretRes = await models.SecretYingshi.findAll() + // 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) { app.fs.logger.error(`sechedule: freshYingshiState, error: ${error}`); } }); return { - freshYingshiState + // freshYingshiState } } \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/schedule/index.js b/code/VideoAccess-VCMP/api/app/lib/schedule/index.js index 1b9b587..6681efa 100644 --- a/code/VideoAccess-VCMP/api/app/lib/schedule/index.js +++ b/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)) { console.info(`定时任务 ${k} 启动`); } - app.fs.utils = { + app.fs.schedule = { ...app.fs.schedule, ...schedule, } diff --git a/code/VideoAccess-VCMP/api/package.json b/code/VideoAccess-VCMP/api/package.json index 834d9ff..8dcbcd7 100644 --- a/code/VideoAccess-VCMP/api/package.json +++ b/code/VideoAccess-VCMP/api/package.json @@ -24,6 +24,7 @@ "koa-proxy": "^0.9.0", "moment": "^2.24.0", "mqtt": "^4.3.7", + "node-schedule": "^2.1.0", "path": "^0.12.7", "path-to-regexp": "^3.0.0", "pg": "^7.9.0",