randomize version_check schedule

This commit is contained in:
simon 2023-01-11 22:00:44 +07:00
parent 7d2bdc58ba
commit 00d7c33af6
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
2 changed files with 25 additions and 13 deletions

View File

@ -52,6 +52,6 @@
"thumbnail_check": {"minute": "0", "hour": "17", "day_of_week": "*"}, "thumbnail_check": {"minute": "0", "hour": "17", "day_of_week": "*"},
"run_backup": {"minute": "0", "hour": "8", "day_of_week": "0"}, "run_backup": {"minute": "0", "hour": "8", "day_of_week": "0"},
"run_backup_rotate": 5, "run_backup_rotate": 5,
"version_check": {"minute": "0", "hour": "11", "day_of_week": "*"} "version_check": "rand-d"
} }
} }

View File

@ -7,6 +7,7 @@ Functionality:
import json import json
import os import os
import re import re
from random import randint
import requests import requests
from celery.schedules import crontab from celery.schedules import crontab
@ -117,6 +118,15 @@ class AppConfig:
self.config["application"]["colors"] = colors self.config["application"]["colors"] = colors
return 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): def load_new_defaults(self):
"""check config.json for missing defaults""" """check config.json for missing defaults"""
default_config = self.get_config_file() default_config = self.get_config_file()
@ -140,6 +150,9 @@ class AppConfig:
# missing nested values # missing nested values
for sub_key, sub_value in value.items(): for sub_key, sub_value in value.items():
if sub_key not in redis_config[key].keys(): 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}) redis_config[key].update({sub_key: sub_value})
needs_update = True needs_update = True
@ -256,19 +269,18 @@ class ScheduleBuilder:
if not item_conf: if not item_conf:
continue continue
minute = item_conf["minute"] schedule_dict.update(
hour = item_conf["hour"] {
day_of_week = item_conf["day_of_week"] f"schedule_{schedule_item}": {
schedule_name = f"schedule_{schedule_item}" "task": schedule_item,
to_add = { "schedule": crontab(
schedule_name: { minute=item_conf["minute"],
"task": schedule_item, hour=item_conf["hour"],
"schedule": crontab( day_of_week=item_conf["day_of_week"],
minute=minute, hour=hour, day_of_week=day_of_week ),
), }
} }
} )
schedule_dict.update(to_add)
return schedule_dict return schedule_dict