Simplify task crontab expression validation (#733)

This commit is contained in:
Wu Clan
2025-07-18 21:11:54 +08:00
committed by GitHub
parent 016361bd68
commit e0a106ec51
3 changed files with 16 additions and 52 deletions
+2 -16
View File
@@ -65,14 +65,7 @@ class TaskSchedulerService:
if task_scheduler:
raise errors.ConflictError(msg='任务调度已存在')
if obj.type == TaskSchedulerType.CRONTAB:
crontab_split = obj.crontab.split(' ')
if len(crontab_split) != 5:
raise errors.RequestError(msg='Crontab 表达式非法')
crontab_verify('m', crontab_split[0])
crontab_verify('h', crontab_split[1])
crontab_verify('dow', crontab_split[2])
crontab_verify('dom', crontab_split[3])
crontab_verify('moy', crontab_split[4])
crontab_verify(obj.crontab)
await task_scheduler_dao.create(db, obj)
@staticmethod
@@ -92,14 +85,7 @@ class TaskSchedulerService:
if await task_scheduler_dao.get_by_name(db, obj.name):
raise errors.ConflictError(msg='任务调度已存在')
if task_scheduler.type == TaskSchedulerType.CRONTAB:
crontab_split = obj.crontab.split(' ')
if len(crontab_split) != 5:
raise errors.RequestError(msg='Crontab 表达式非法')
crontab_verify('m', crontab_split[0])
crontab_verify('h', crontab_split[1])
crontab_verify('dow', crontab_split[2])
crontab_verify('dom', crontab_split[3])
crontab_verify('moy', crontab_split[4])
crontab_verify(obj.crontab)
count = await task_scheduler_dao.update(db, pk, obj)
return count