Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions backend/app/task/utils/tzcrontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

from celery import schedules
from celery.schedules import ParseException, crontab_parser
from celery.schedules import ParseException, crontab

from backend.common.exception import errors
from backend.utils.timezone import timezone
Expand Down Expand Up @@ -52,22 +52,17 @@ def __reduce__(self) -> tuple[type, tuple[str, str, str, str, str], None]:
)


def crontab_verify(crontab: str) -> None:
def crontab_verify(crontab_str: str) -> None:
"""
验证 Celery crontab 表达式

:param crontab: 计划表达式
:param crontab_str: 计划表达式
:return:
"""
crontab_split = crontab.split(' ')
crontab_split = crontab_str.split(' ')
if len(crontab_split) != 5:
raise errors.RequestError(msg='Crontab 表达式非法')

try:
crontab_parser(60, 0).parse(crontab_split[0]) # minute
crontab_parser(24, 0).parse(crontab_split[1]) # hour
crontab_parser(7, 0).parse(crontab_split[2]) # day_of_week
crontab_parser(31, 1).parse(crontab_split[3]) # day_of_month
crontab_parser(12, 1).parse(crontab_split[4]) # month_of_year
crontab(*crontab_split)
except ParseException:
raise errors.RequestError(msg='Crontab 表达式非法')