fix: isolate invalid cron rules during scheduler recovery

This commit is contained in:
whyour
2026-09-27 16:45:09 +08:00
parent a8310e7d51
commit bf63425805
12 changed files with 211 additions and 41 deletions
+2 -13
View File
@@ -1,5 +1,5 @@
import { Joi } from 'celebrate';
import CronExpressionParser from 'cron-parser';
import { isValidCronSchedule } from '../shared/cronSchedule';
import { ScheduleType } from '../interface/schedule';
import path from 'path';
import config from '../config';
@@ -12,18 +12,7 @@ const validateSchedule = (value: string, helpers: any) => {
return value;
}
// 检测裸 /N 模式:cron-parser 会接受,但 node-schedule 会返回 null
// 提前拦截,避免任务入库后调度器注册失败
if (/\s\/\d/.test(value) || /^\/\d/.test(value)) {
return helpers.error('any.invalid');
}
try {
if (CronExpressionParser.parse(value).hasNext()) {
return value;
}
} catch (e) {
return helpers.error('any.invalid');
}
if (isValidCronSchedule(value)) return value;
return helpers.error('any.invalid');
};