From 00d7c33af63c9e1f3fe650cf39ed2eec9963f6ae Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 11 Jan 2023 22:00:44 +0700 Subject: [PATCH] randomize version_check schedule --- tubearchivist/home/config.json | 2 +- tubearchivist/home/src/ta/config.py | 36 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index aa446399..420e27b8 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -52,6 +52,6 @@ "thumbnail_check": {"minute": "0", "hour": "17", "day_of_week": "*"}, "run_backup": {"minute": "0", "hour": "8", "day_of_week": "0"}, "run_backup_rotate": 5, - "version_check": {"minute": "0", "hour": "11", "day_of_week": "*"} + "version_check": "rand-d" } } diff --git a/tubearchivist/home/src/ta/config.py b/tubearchivist/home/src/ta/config.py index abd44758..3b9a77b0 100644 --- a/tubearchivist/home/src/ta/config.py +++ b/tubearchivist/home/src/ta/config.py @@ -7,6 +7,7 @@ Functionality: import json import os import re +from random import randint import requests from celery.schedules import crontab @@ -117,6 +118,15 @@ class AppConfig: self.config["application"]["colors"] = colors return colors + @staticmethod + def _build_rand_daily(): + """build random daily schedule per installation""" + return { + "minute": randint(0, 59), + "hour": randint(0, 23), + "day_of_week": "*", + } + def load_new_defaults(self): """check config.json for missing defaults""" default_config = self.get_config_file() @@ -140,6 +150,9 @@ class AppConfig: # missing nested values for sub_key, sub_value in value.items(): if sub_key not in redis_config[key].keys(): + if sub_value == "rand-d": + sub_value = self._build_rand_daily() + redis_config[key].update({sub_key: sub_value}) needs_update = True @@ -256,19 +269,18 @@ class ScheduleBuilder: if not item_conf: continue - minute = item_conf["minute"] - hour = item_conf["hour"] - day_of_week = item_conf["day_of_week"] - schedule_name = f"schedule_{schedule_item}" - to_add = { - schedule_name: { - "task": schedule_item, - "schedule": crontab( - minute=minute, hour=hour, day_of_week=day_of_week - ), + schedule_dict.update( + { + f"schedule_{schedule_item}": { + "task": schedule_item, + "schedule": crontab( + minute=item_conf["minute"], + hour=item_conf["hour"], + day_of_week=item_conf["day_of_week"], + ), + } } - } - schedule_dict.update(to_add) + ) return schedule_dict