新增 连续重复启动中断

This commit is contained in:
Suwings 2022-01-29 16:23:18 +08:00
parent 6affd14af2
commit fcad1e9c28
4 changed files with 18 additions and 6 deletions

View File

@ -93,8 +93,6 @@ export default class DockerStartCommand extends InstanceCommand {
}
async exec(instance: Instance, source = "Unknown") {
const instanceStatus = instance.status();
if (instanceStatus != Instance.STATUS_STOP) return instance.failure(new StartupDockerProcessError("实例未处于关闭状态,无法再进行启动"));
if (!instance.config.startCommand || !instance.config.cwd || !instance.config.ie || !instance.config.oe) return instance.failure(new StartupDockerProcessError("启动命令,输入输出编码或工作目录为空值"));
if (!fs.existsSync(instance.absoluteCwdPath())) return instance.failure(new StartupDockerProcessError("工作目录并不存在"));

View File

@ -86,7 +86,7 @@ class ProcessAdapter extends EventEmitter implements IInstanceProcess {
this.process.stdout.destroy();
this.process.stderr.destroy();
}
} catch (error) { }
} catch (error) {}
}
}
@ -96,8 +96,6 @@ export default class GeneralStartCommand extends InstanceCommand {
}
async exec(instance: Instance, source = "Unknown") {
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 (!fs.existsSync(instance.absoluteCwdPath())) return instance.failure(new StartupError("工作目录并不存在"));

View File

@ -48,13 +48,28 @@ export default class StartCommand extends InstanceCommand {
}
async exec(instance: Instance) {
// 状态检查
const instanceStatus = instance.status();
if (instanceStatus !== Instance.STATUS_STOP) return instance.failure(new StartupError("实例未处于关闭状态,无法再进行启动"));
// 到期时间检查
const endTime = new Date(instance.config.endTime).getTime();
if (endTime) {
const currentTime = new Date().getTime();
if (endTime <= currentTime) {
throw new Error("实例使用到期时间已到,无法再启动实例");
return instance.failure(new Error("实例使用到期时间已到,无法再启动实例"));
}
}
// 无限启动检查
const currentTimestamp = new Date().getTime();
const intervals = 3 * 1000;
if (instance.startTimestamp && currentTimestamp - instance.startTimestamp < intervals) {
return instance.failure(new Error("两次启动时间间隔太短,本次请求被拒绝,请稍后重试"));
}
// 更新上次启动时间戳
instance.startTimestamp = currentTimestamp;
return await instance.execPreset("start", this.source);
}
}

View File

@ -67,6 +67,7 @@ export default class Instance extends EventEmitter {
public instanceUuid: string;
public lock: boolean;
public startCount: number;
public startTimestamp: number = 0;
// 生命周期任务,定时任务管理器
public readonly lifeCycleTaskManager = new LifeCycleTaskManager(this);