From 4d6398b7e55872c22e19e9161e88d2f0d24dd711 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 20 Jun 2022 15:39:35 +0800 Subject: [PATCH] dockerfile --- code/VideoAccess-VCMP/api/Dockerfile | 5 +--- .../api/app/lib/controllers/camera/index.js | 5 ++++ code/VideoAccess-VCMP/api/app/lib/index.js | 4 +++ .../api/app/lib/schedule/freshYingshiState.js | 25 +++++++++++++++++++ .../api/app/lib/schedule/index.js | 18 +++++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js create mode 100644 code/VideoAccess-VCMP/api/app/lib/schedule/index.js diff --git a/code/VideoAccess-VCMP/api/Dockerfile b/code/VideoAccess-VCMP/api/Dockerfile index db8924c..b64fd4f 100644 --- a/code/VideoAccess-VCMP/api/Dockerfile +++ b/code/VideoAccess-VCMP/api/Dockerfile @@ -9,11 +9,8 @@ EXPOSE 8080 RUN npm config set registry=http://10.8.30.22:7000 RUN echo "{\"time\":\"$BUILD_TIMESTAMP\",\"build\": \"$BUILD_NUMBER\",\"revision\": \"$SVN_REVISION_1\",\"URL\":\"$SVN_URL_1\"}" > version.json RUN npm cache clean -f +RUN rm -rf package-lock.json RUN npm install --registry http://10.8.30.22:7000 -RUN npm run build -RUN rm -rf client/src -RUN rm -rf node_modules -RUN npm install --production --registry http://10.8.30.22:7000 FROM registry.cn-hangzhou.aliyuncs.com/fs-devops/node-16:7.22-06-20 diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js index 188b10c..e4e8667 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/camera/index.js @@ -159,6 +159,11 @@ async function detail (ctx) { const cameraRes = await models.Camera.findOne({ where: { id: cameraId + }, + include: { + model: models.GbCamera, + attributes: ['id', 'online'], + required: false } }) diff --git a/code/VideoAccess-VCMP/api/app/lib/index.js b/code/VideoAccess-VCMP/api/app/lib/index.js index 09ccd95..0f5456d 100644 --- a/code/VideoAccess-VCMP/api/app/lib/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/index.js @@ -7,6 +7,7 @@ const socketConect = require('./service/socket') const mqttVideoServer = require('./service/mqttVideoServer') const paasRequest = require('./service/paasRequest'); const authenticator = require('./middlewares/authenticator'); +const schedule = require('./schedule') // const apiLog = require('./middlewares/api-log'); module.exports.entry = function (app, router, opts) { @@ -28,6 +29,9 @@ module.exports.entry = function (app, router, opts) { // 工具类函数 utils(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 new file mode 100644 index 0000000..acdc492 --- /dev/null +++ b/code/VideoAccess-VCMP/api/app/lib/schedule/freshYingshiState.js @@ -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 + } +} \ 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 new file mode 100644 index 0000000..1b9b587 --- /dev/null +++ b/code/VideoAccess-VCMP/api/app/lib/schedule/index.js @@ -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, + } + } + }); +};