优化 代码格式

This commit is contained in:
Suwings 2021-07-07 14:18:52 +08:00
parent 4dcc2ed0ad
commit 51a312d12f
3 changed files with 29 additions and 23 deletions

View File

@ -29,10 +29,8 @@ export default class StartCommand extends InstanceCommand {
exec(instance: Instance) {
const instanceStatus = instance.status();
if (instanceStatus != Instance.STATUS_STOP)
return instance.failure(new StartupError("实例未处于关闭状态,无法再进行启动"));
if (!instance.config.startCommand || !instance.config.cwd || !instance.config.ie || !instance.config.oe)
return instance.failure(new StartupError("启动命令,输入输出编码或工作目录为空值"));
if (instanceStatus != Instance.STATUS_STOP) return instance.failure(new StartupError("实例未处于关闭状态,无法再进行启动"));
if (!instance.config.startCommand || !instance.config.cwd || !instance.config.ie || !instance.config.oe) return instance.failure(new StartupError("启动命令,输入输出编码或工作目录为空值"));
try {
instance.setLock(true);
@ -41,7 +39,7 @@ export default class StartCommand extends InstanceCommand {
// 启动次数增加
instance.startCount++;
// 命令解析
const commandList = instance.config.startCommand.replace(/ /igm, " ").split(" ");
const commandList = instance.config.startCommand.replace(/ /gim, " ").split(" ");
const commandExeFile = commandList[0];
const commnadParameters = commandList.slice(1);

View File

@ -11,8 +11,6 @@ import RouterContext from "../entity/ctx";
import * as protocol from "../service/protocol";
import InstanceSubsystem from "../service/system_instance";
// 程序输出流日志广播
InstanceSubsystem.on("data", (instanceUuid: string, text: string) => {
InstanceSubsystem.forEachForward(instanceUuid, (socket) => {
@ -39,7 +37,6 @@ InstanceSubsystem.on("open", (obj: any) => {
});
});
// 实例失败事件(一般用于启动失败,也可能是其他操作失败)
InstanceSubsystem.on("failure", (obj: any) => {
protocol.broadcast("instance/failure", {
@ -47,4 +44,3 @@ InstanceSubsystem.on("failure", (obj: any) => {
instanceName: obj.instanceName
});
});

View File

@ -58,22 +58,34 @@ class InstanceSubsystem extends EventEmitter {
this.emit("data", instance.instanceUuid, ...arr);
});
instance.on("exit", (...arr) => {
this.emit("exit", {
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
}, ...arr);
this.emit(
"exit",
{
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
},
...arr
);
});
instance.on("open", (...arr) => {
this.emit("open", {
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
}, ...arr);
this.emit(
"open",
{
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
},
...arr
);
});
instance.on("failure", (...arr) => {
this.emit("failure", {
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
}, ...arr);
this.emit(
"failure",
{
instanceUuid: instance.instanceUuid,
instanceName: instance.config.nickname
},
...arr
);
});
}
@ -88,13 +100,13 @@ class InstanceSubsystem extends EventEmitter {
forward(targetInstanceUuid: string, socket: Socket) {
try {
this.instanceStream.requestForward(socket, targetInstanceUuid);
} catch (err) { }
} catch (err) {}
}
stopForward(targetInstanceUuid: string, socket: Socket) {
try {
this.instanceStream.cannelForward(socket, targetInstanceUuid);
} catch (err) { }
} catch (err) {}
}
forEachForward(instanceUuid: string, callback: (socket: Socket) => void) {