Feat: 去除最大压缩任务量

This commit is contained in:
Suwings 2022-07-03 16:49:03 +08:00
parent ff89d374f3
commit 4440befeb0
2 changed files with 30 additions and 20 deletions

View File

@ -55,5 +55,12 @@ class GlobalConfiguration {
StorageSubsystem.store("Config", GlobalConfiguration.ID, this.config); StorageSubsystem.store("Config", GlobalConfiguration.ID, this.config);
} }
} }
class GlobalEnv {
public fileTaskCount = 0;
}
const globalConfiguration = new GlobalConfiguration(); const globalConfiguration = new GlobalConfiguration();
export { globalConfiguration, Config }; const globalEnv = new GlobalEnv();
export { globalConfiguration, Config, globalEnv };

View File

@ -23,6 +23,7 @@ import * as protocol from "../service/protocol";
import { routerApp } from "../service/router"; import { routerApp } from "../service/router";
import InstanceSubsystem from "../service/system_instance"; import InstanceSubsystem from "../service/system_instance";
import { getFileManager } from "../service/file_router_service"; import { getFileManager } from "../service/file_router_service";
import { globalEnv } from "../entity/config";
// 部分路由器操作路由器验证中间件 // 部分路由器操作路由器验证中间件
routerApp.use((event, ctx, data, next) => { routerApp.use((event, ctx, data, next) => {
@ -130,32 +131,34 @@ routerApp.on("file/compress", async (ctx, data) => {
const code = data.code; const code = data.code;
const fileManager = getFileManager(data.instanceUuid); const fileManager = getFileManager(data.instanceUuid);
const instance = InstanceSubsystem.getInstance(data.instanceUuid); const instance = InstanceSubsystem.getInstance(data.instanceUuid);
if (instance.info.fileLock !== 0) { // if (instance.info.fileLock !== 0) {
throw new Error("超出最大同时解压缩任务量,请等待其他解压缩任务完成后再执行。"); // 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) { if (type === 1) {
// 异步执行
fileManager fileManager
.zip(source, targets, code) .zip(source, targets, code)
.then(() => { .then(() => {})
instance.info.fileLock = 0; .catch((error) => protocol.responseError(ctx, error))
}) .finally(fileTaskEnd);
.catch((error) => {
instance.info.fileLock = 0;
protocol.responseError(ctx, error);
});
} else { } else {
// 异步执行
fileManager fileManager
.unzip(source, targets, code) .unzip(source, targets, code)
.then(() => { .then(() => {})
instance.info.fileLock = 0; .catch((error) => protocol.responseError(ctx, error))
}) .finally(fileTaskEnd);
.catch((error) => {
instance.info.fileLock = 0;
protocol.responseError(ctx, error);
});
} }
protocol.response(ctx, true); protocol.response(ctx, true);
} catch (error) { } catch (error) {