Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit c504293

Browse files
committed
重构 格式化代码
1 parent bf79683 commit c504293

File tree

2 files changed

+33
-38
lines changed

2 files changed

+33
-38
lines changed

src/entity/commands/docker/docker _start.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ export class DockerProcessAdapter extends EventEmitter implements IInstanceProce
8181
public async destroy() {
8282
try {
8383
await this.container.remove();
84-
} catch (error) {
85-
}
84+
} catch (error) {}
8685
}
8786

8887
private wait() {
@@ -99,10 +98,8 @@ export default class DockerStartCommand extends InstanceCommand {
9998
}
10099

101100
async exec(instance: Instance, source = "Unknown") {
102-
if (!instance.config.startCommand || !instance.config.cwd || !instance.config.ie || !instance.config.oe)
103-
return instance.failure(new StartupDockerProcessError("启动命令,输入输出编码或工作目录为空值"));
104-
if (!fs.existsSync(instance.absoluteCwdPath()))
105-
return instance.failure(new StartupDockerProcessError("工作目录并不存在"));
101+
if (!instance.config.startCommand || !instance.config.cwd || !instance.config.ie || !instance.config.oe) return instance.failure(new StartupDockerProcessError("启动命令,输入输出编码或工作目录为空值"));
102+
if (!fs.existsSync(instance.absoluteCwdPath())) return instance.failure(new StartupDockerProcessError("工作目录并不存在"));
106103

107104
try {
108105
// 锁死实例
@@ -145,23 +142,25 @@ export default class DockerStartCommand extends InstanceCommand {
145142
// 解析额外路径挂载
146143
const extraVolumes = instance.config.docker.extraVolumes;
147144
const extraBinds = [];
148-
for (let it of extraVolumes) {
149-
if (!it) continue;
150-
const element = it.split(":");
151-
if (element.length != 2) continue;
152-
let [hostPath, containerPath] = element;
145+
if (extraVolumes) {
146+
for (let it of extraVolumes) {
147+
if (!it) continue;
148+
const element = it.split(":");
149+
if (element.length != 2) continue;
150+
let [hostPath, containerPath] = element;
153151

154-
if (path.isAbsolute(containerPath)) {
155-
containerPath = path.normalize(containerPath);
156-
} else {
157-
containerPath = path.normalize(path.join("/workspace/", containerPath));
158-
}
159-
if (path.isAbsolute(hostPath)) {
160-
hostPath = path.normalize(hostPath);
161-
} else {
162-
hostPath = path.normalize(path.join(process.cwd(), hostPath));
152+
if (path.isAbsolute(containerPath)) {
153+
containerPath = path.normalize(containerPath);
154+
} else {
155+
containerPath = path.normalize(path.join("/workspace/", containerPath));
156+
}
157+
if (path.isAbsolute(hostPath)) {
158+
hostPath = path.normalize(hostPath);
159+
} else {
160+
hostPath = path.normalize(path.join(process.cwd(), hostPath));
161+
}
162+
extraBinds.push(`${hostPath}:${containerPath}`);
163163
}
164-
extraBinds.push(`${hostPath}:${containerPath}`);
165164
}
166165

167166
// 内存限制
@@ -202,8 +201,7 @@ export default class DockerStartCommand extends InstanceCommand {
202201
logger.info(`工作目录: ${cwd}`);
203202
logger.info(`网络模式: ${instance.config.docker.networkMode}`);
204203
logger.info(`端口映射: ${JSON.stringify(publicPortArray)}`);
205-
if(extraBinds.length > 0)
206-
logger.info(`额外挂载: ${JSON.stringify(extraBinds)}`);
204+
if (extraBinds.length > 0) logger.info(`额外挂载: ${JSON.stringify(extraBinds)}`);
207205
logger.info(`网络别名: ${JSON.stringify(instance.config.docker.networkAliases)}`);
208206
if (maxMemory) logger.info(`内存限制: ${maxMemory} MB`);
209207
logger.info(`类型: Docker 容器`);
@@ -237,7 +235,7 @@ export default class DockerStartCommand extends InstanceCommand {
237235
NetworkingConfig: {
238236
EndpointsConfig: {
239237
[instance.config.docker.networkMode]: {
240-
"Aliases": instance.config.docker.networkAliases
238+
Aliases: instance.config.docker.networkAliases
241239
}
242240
}
243241
}

src/service/system_instance.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ class InstanceSubsystem extends EventEmitter {
7878
// 所有实例全部进行功能调度器
7979
instance
8080
.forceExec(new FuntionDispatcher())
81-
.then((v) => {
82-
})
83-
.catch((v) => {
84-
});
81+
.then((v) => {})
82+
.catch((v) => {});
8583
this.addInstance(instance);
8684
});
8785
// 处理自动启动
@@ -161,8 +159,7 @@ class InstanceSubsystem extends EventEmitter {
161159
// 删除计划任务
162160
InstanceControl.deleteInstanceAllTask(instanceUuid);
163161
// 异步删除文件
164-
if (deleteFile) fs.remove(instance.config.cwd, (err) => {
165-
});
162+
if (deleteFile) fs.remove(instance.config.cwd, (err) => {});
166163
return true;
167164
}
168165
throw new Error("Instance does not exist");
@@ -171,15 +168,13 @@ class InstanceSubsystem extends EventEmitter {
171168
forward(targetInstanceUuid: string, socket: Socket) {
172169
try {
173170
this.instanceStream.requestForward(socket, targetInstanceUuid);
174-
} catch (err) {
175-
}
171+
} catch (err) {}
176172
}
177173

178174
stopForward(targetInstanceUuid: string, socket: Socket) {
179175
try {
180176
this.instanceStream.cannelForward(socket, targetInstanceUuid);
181-
} catch (err) {
182-
}
177+
} catch (err) {}
183178
}
184179

185180
forEachForward(instanceUuid: string, callback: (socket: Socket) => void) {
@@ -206,10 +201,12 @@ class InstanceSubsystem extends EventEmitter {
206201
const instance = iterator[1];
207202
if (instance.status() != Instance.STATUS_STOP) {
208203
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) is running or busy, and is being forced to end.`);
209-
promises.push(instance.execCommand(new KillCommand()).then(() => {
210-
StorageSubsystem.store("InstanceConfig", instance.instanceUuid, instance.config);
211-
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) saved successfully.`);
212-
}));
204+
promises.push(
205+
instance.execCommand(new KillCommand()).then(() => {
206+
StorageSubsystem.store("InstanceConfig", instance.instanceUuid, instance.config);
207+
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) saved successfully.`);
208+
})
209+
);
213210
}
214211
}
215212
await Promise.all(promises);

0 commit comments

Comments
 (0)