修改定时规则类型

This commit is contained in:
whyour
2025-02-21 01:35:08 +08:00
parent 8173075b67
commit fa83761d27
7 changed files with 116 additions and 87 deletions
+13
View File
@@ -0,0 +1,13 @@
export enum ScheduleType {
BOOT = '@boot',
ONCE = '@once',
}
export type ScheduleValidator = (schedule?: string) => boolean;
export type CronSchedulerPayload = {
name: string;
id: string;
schedule: string;
command: string;
extra_schedules: Array<{ schedule: string }>;
};
+3 -2
View File
@@ -22,6 +22,7 @@ import dayjs from 'dayjs';
import pickBy from 'lodash/pickBy';
import omit from 'lodash/omit';
import { writeFileWithLock } from '../shared/utils';
import { ScheduleType } from '../interface/schedule';
@Service()
export default class CronService {
@@ -36,11 +37,11 @@ export default class CronService {
}
private isOnceSchedule(schedule?: string) {
return schedule?.startsWith('@once');
return schedule?.startsWith(ScheduleType.ONCE);
}
private isBootSchedule(schedule?: string) {
return schedule?.startsWith('@boot');
return schedule?.startsWith(ScheduleType.BOOT);
}
private isSpecialSchedule(schedule?: string) {
+5 -1
View File
@@ -1,8 +1,12 @@
import { Joi } from 'celebrate';
import cron_parser from 'cron-parser';
import { ScheduleType } from '../interface/schedule';
const validateSchedule = (value: string, helpers: any) => {
if (value.startsWith('@once') || value.startsWith('@boot')) {
if (
value.startsWith(ScheduleType.ONCE) ||
value.startsWith(ScheduleType.BOOT)
) {
return value;
}