mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-04 19:30:13 +00:00
validate form entries, set auto sensible default
This commit is contained in:
parent
ab8dc0ddee
commit
0b0634273a
@ -156,13 +156,13 @@ class AppConfig:
|
|||||||
class ScheduleBuilder:
|
class ScheduleBuilder:
|
||||||
"""build schedule dicts for beat"""
|
"""build schedule dicts for beat"""
|
||||||
|
|
||||||
SCHEDULES = [
|
SCHEDULES = {
|
||||||
"update_subscribed",
|
"update_subscribed": "0 8 *",
|
||||||
"download_pending",
|
"download_pending": "0 16 *",
|
||||||
"check_reindex",
|
"check_reindex": "0 12 *",
|
||||||
"thumbnail_check",
|
"thumbnail_check": "0 17 *",
|
||||||
"run_backup",
|
"run_backup": "0 18 0",
|
||||||
]
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config = AppConfig().config
|
self.config = AppConfig().config
|
||||||
@ -172,16 +172,35 @@ class ScheduleBuilder:
|
|||||||
print("processing form, restart container for changes to take effect")
|
print("processing form, restart container for changes to take effect")
|
||||||
redis_config = self.config
|
redis_config = self.config
|
||||||
for key, value in form_post.items():
|
for key, value in form_post.items():
|
||||||
if key in self.SCHEDULES and value[0]:
|
to_check = value[0]
|
||||||
print(f"change schedule for {key} to {value[0]}")
|
if key in self.SCHEDULES.keys() and to_check:
|
||||||
if value[0] == "0":
|
to_write = self.value_builder(key, to_check)
|
||||||
to_write = False
|
|
||||||
else:
|
|
||||||
keys = ["minute", "hour", "day_of_week"]
|
|
||||||
to_write = dict(zip(keys, value[0].split()))
|
|
||||||
redis_config["scheduler"][key] = to_write
|
redis_config["scheduler"][key] = to_write
|
||||||
RedisArchivist().set_message("config", redis_config, expire=False)
|
RedisArchivist().set_message("config", redis_config, expire=False)
|
||||||
|
|
||||||
|
def value_builder(self, key, to_check):
|
||||||
|
"""validate single cron form entry and return cron dict"""
|
||||||
|
print(f"change schedule for {key} to {to_check}")
|
||||||
|
if to_check == "0":
|
||||||
|
# deactivate this schedule
|
||||||
|
return False
|
||||||
|
|
||||||
|
keys = ["minute", "hour", "day_of_week"]
|
||||||
|
if to_check == "auto":
|
||||||
|
# set to sensible default
|
||||||
|
values = self.SCHEDULES[key].split()
|
||||||
|
else:
|
||||||
|
values = to_check.split()
|
||||||
|
|
||||||
|
if len(keys) != len(values):
|
||||||
|
raise ValueError(f"failed to parse {to_check} for {key}")
|
||||||
|
|
||||||
|
to_write = dict(zip(keys, values))
|
||||||
|
if "*" in to_write["minute"]:
|
||||||
|
raise ValueError("too frequent: wildcard in minutes not supported")
|
||||||
|
|
||||||
|
return to_write
|
||||||
|
|
||||||
def build_schedule(self):
|
def build_schedule(self):
|
||||||
"""build schedule dict as expected by app.conf.beat_schedule"""
|
"""build schedule dict as expected by app.conf.beat_schedule"""
|
||||||
schedule_dict = {}
|
schedule_dict = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user