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

Commit 574980f

Browse files
committed
新增 计划任务上限数
1 parent f5894be commit 574980f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/routers/schedule_router.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@ import InstanceControlSubsystem from "../service/system_instance_control";
2525

2626
// 创建计划任务
2727
routerApp.on("schedule/register", (ctx, data) => {
28-
InstanceControlSubsystem.registerScheduleJob(data);
29-
protocol.response(ctx, true);
28+
try {
29+
InstanceControlSubsystem.registerScheduleJob(data);
30+
protocol.response(ctx, true);
31+
} catch (error) {
32+
protocol.responseError(ctx, error);
33+
}
3034
});
3135

3236
// 获取任务列表

src/service/system_instance_control.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ class InstanceControlSubsystem {
9191
if (!this.taskMap.has(key)) {
9292
this.taskMap.set(key, []);
9393
}
94+
if (this.taskMap.get(key)?.length > 8) throw new Error("无法继续创建计划任务,以达到上限");
9495
if (!this.checkTask(key, task.name)) throw new Error("已存在重复的任务");
95-
let job: IScheduleJob;
9696
if (needStore) logger.info(`创建计划任务 ${task.name}:\n${JSON.stringify(task)}`);
9797

98+
let job: IScheduleJob;
99+
98100
// 最小间隔时间检查
99101
if (task.type === 1) {
100102
let internalTime = Number(task.time);
@@ -232,6 +234,11 @@ class InstanceControlSubsystem {
232234
}
233235
}
234236
}
237+
238+
private checkScheduledTaskLimit(instanceUuid: string) {
239+
for (const iterator of this.taskMap) {
240+
}
241+
}
235242
}
236243

237244
export default new InstanceControlSubsystem();

0 commit comments

Comments
 (0)