mirror of
https://github.com/fastapi-practices/fastapi-best-architecture.git
synced 2026-09-21 21:15:13 +00:00
Simplify task crontab expression validation (#733)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user