Fix: 超长实例启动等待

This commit is contained in:
Suwings 2022-07-30 12:11:09 +08:00
parent a135e55afe
commit e6646889c5
2 changed files with 11 additions and 9 deletions

View File

@ -17,8 +17,7 @@ __ / / / __ / _ \\_ __ __ \\ __ \\_ __ \\
_ /_/ // /_/ // __/ / / / / / /_/ / / / /
/_____/ \\__,_/ \\___//_/ /_/ /_/\\____//_/ /_/
+ Released under the AGPL-3.0 License
+ Copyright 2022 Suwings
+ Copyright 2022 https://github.com/mcsmanager
+ Version ${VERSION}
`);
@ -119,6 +118,7 @@ console.log("");
// 装载 终端界面UI
import "./service/ui";
["SIGTERM", "SIGINT", "SIGQUIT"].forEach(function (sig) {
process.on(sig, async function () {
try {

View File

@ -22,6 +22,12 @@ export default class StartCommand extends InstanceCommand {
this.source = source;
}
private async sleep() {
return new Promise((ok) => {
setTimeout(ok, 1000 * 3);
});
}
async exec(instance: Instance) {
// 状态检查
const instanceStatus = instance.status();
@ -36,16 +42,12 @@ export default class StartCommand extends InstanceCommand {
}
}
// 无限启动检查
const currentTimestamp = new Date().getTime();
const intervals = 10 * 1000;
if (instance.startTimestamp && currentTimestamp - instance.startTimestamp < intervals) {
const unbanss = Number((intervals - (currentTimestamp - instance.startTimestamp)) / 1000).toFixed(0);
return instance.failure(new Error(`两次启动间隔太短,本次请求被拒绝,请 ${unbanss} 秒后再试`));
}
// 更新上次启动时间戳
instance.startTimestamp = currentTimestamp;
instance.println("INFO", "正在启动实例...");
await this.sleep();
return await instance.execPreset("start", this.source);
}
}