From 1a957979974ccb46b79a25a0220e480f991ebf19 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 8 Jan 2022 20:04:51 +0700 Subject: [PATCH] improve scheduler validation with regex, #126 --- tubearchivist/home/src/config.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tubearchivist/home/src/config.py b/tubearchivist/home/src/config.py index d35c63d..5690716 100644 --- a/tubearchivist/home/src/config.py +++ b/tubearchivist/home/src/config.py @@ -7,6 +7,7 @@ Functionality: import json import os +import re from celery.schedules import crontab from home.src.helper import RedisArchivist @@ -206,6 +207,10 @@ class ScheduleBuilder: if to_check == "0": # deactivate this schedule return False + if re.search(r"[\d]{1,2}\/[\d]{1,2}", to_check): + # number/number cron format will fail in celery + print("number/number schedule formatting not supported") + raise ValueError keys = ["minute", "hour", "day_of_week"] if to_check == "auto": @@ -219,8 +224,11 @@ class ScheduleBuilder: raise ValueError("invalid input") to_write = dict(zip(keys, values)) - if "*" in to_write["minute"]: - raise ValueError("too frequent: wildcard in minutes not supported") + try: + int(to_write["minute"]) + except ValueError as error: + print("too frequent: only number in minutes are supported") + raise ValueError("invalid input") from error return to_write