From 4440befeb012ca71896d33a0403293350d655548 Mon Sep 17 00:00:00 2001 From: Suwings Date: Sun, 3 Jul 2022 16:49:03 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=E5=8E=BB=E9=99=A4=E6=9C=80=E5=A4=A7?= =?UTF-8?q?=E5=8E=8B=E7=BC=A9=E4=BB=BB=E5=8A=A1=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entity/config.ts | 9 ++++++++- src/routers/file_router.ts | 41 ++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/entity/config.ts b/src/entity/config.ts index 28af885..6f043fc 100644 --- a/src/entity/config.ts +++ b/src/entity/config.ts @@ -55,5 +55,12 @@ class GlobalConfiguration { StorageSubsystem.store("Config", GlobalConfiguration.ID, this.config); } } + +class GlobalEnv { + public fileTaskCount = 0; +} + const globalConfiguration = new GlobalConfiguration(); -export { globalConfiguration, Config }; +const globalEnv = new GlobalEnv(); + +export { globalConfiguration, Config, globalEnv }; diff --git a/src/routers/file_router.ts b/src/routers/file_router.ts index 5511bec..f35703a 100644 --- a/src/routers/file_router.ts +++ b/src/routers/file_router.ts @@ -23,6 +23,7 @@ import * as protocol from "../service/protocol"; import { routerApp } from "../service/router"; import InstanceSubsystem from "../service/system_instance"; import { getFileManager } from "../service/file_router_service"; +import { globalEnv } from "../entity/config"; // 部分路由器操作路由器验证中间件 routerApp.use((event, ctx, data, next) => { @@ -130,32 +131,34 @@ routerApp.on("file/compress", async (ctx, data) => { const code = data.code; const fileManager = getFileManager(data.instanceUuid); const instance = InstanceSubsystem.getInstance(data.instanceUuid); - if (instance.info.fileLock !== 0) { - throw new Error("超出最大同时解压缩任务量,请等待其他解压缩任务完成后再执行。"); + // if (instance.info.fileLock !== 0) { + // throw new Error("超出最大同时解压缩任务量,请等待其他解压缩任务完成后再执行。"); + // } + + // 单个实例文件任务量与整个守护进程文件任务量数统计 + function fileTaskStart() { + instance.info.fileLock++; + globalEnv.fileTaskCount++; } - instance.info.fileLock = 1; + function fileTaskEnd() { + instance.info.fileLock--; + globalEnv.fileTaskCount--; + } + + // 开始解压或压缩文件 + fileTaskStart(); if (type === 1) { - // 异步执行 fileManager .zip(source, targets, code) - .then(() => { - instance.info.fileLock = 0; - }) - .catch((error) => { - instance.info.fileLock = 0; - protocol.responseError(ctx, error); - }); + .then(() => {}) + .catch((error) => protocol.responseError(ctx, error)) + .finally(fileTaskEnd); } else { - // 异步执行 fileManager .unzip(source, targets, code) - .then(() => { - instance.info.fileLock = 0; - }) - .catch((error) => { - instance.info.fileLock = 0; - protocol.responseError(ctx, error); - }); + .then(() => {}) + .catch((error) => protocol.responseError(ctx, error)) + .finally(fileTaskEnd); } protocol.response(ctx, true); } catch (error) {