forked from mirror/MCSM-Daemon
Feat: 去除最大压缩任务量
This commit is contained in:
parent
ff89d374f3
commit
4440befeb0
@ -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 };
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user