mirror of
https://github.com/whyour/qinglong.git
synced 2026-06-28 02:45:08 +08:00
过滤 delCron 中 scheduleStacks 的 null job
nodeSchedule.scheduleJob() 对无效 cron 表达式(如 "0 * /6 * * *", 空格分开了 * /6)会返回 null,原代码原样存入 scheduleStacks 数组。 delCron 取消时对 null 调 cancel() 抛出 UNKNOWN 错误,导致 gRPC handler 中断、HTTP 端 cronService.remove() 跳过 setCrontab(), crontab.list 残留已删任务的记录,导致订阅更新时 gen_list_repo() 误判脚本已存在、不再重新注册。 过滤 null 并对每个 cancel 调用加 try/catch 容错。
This commit is contained in:
parent
fc355bc86f
commit
50d6f3fb23
|
|
@ -13,7 +13,20 @@ const delCron = (
|
||||||
'[schedule][取消定时任务] 任务ID: %s',
|
'[schedule][取消定时任务] 任务ID: %s',
|
||||||
id,
|
id,
|
||||||
);
|
);
|
||||||
scheduleStacks.get(id)?.forEach(x => x.cancel());
|
// 过滤掉 nodeSchedule.scheduleJob() 对无效表达式返回的 null,
|
||||||
|
// 否则对 null 调 cancel() 会让整个取消流程抛出 UNKNOWN 错误,
|
||||||
|
// 进而导致 HTTP 端的 remove() 跳过 setCrontab(),造成 crontab.list 残留。
|
||||||
|
scheduleStacks.get(id)?.filter((x) => x != null).forEach((x) => {
|
||||||
|
try {
|
||||||
|
x.cancel();
|
||||||
|
} catch (error: any) {
|
||||||
|
Logger.warn(
|
||||||
|
'[schedule][取消任务失败] 任务ID: %s, 错误: %s',
|
||||||
|
id,
|
||||||
|
error?.message || error,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
scheduleStacks.delete(id);
|
scheduleStacks.delete(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user