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": "*"},
"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"
}
}

View File

@ -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: {
schedule_dict.update(
{
f"schedule_{schedule_item}": {
"task": schedule_item,
"schedule": crontab(
minute=minute, hour=hour, day_of_week=day_of_week
minute=item_conf["minute"],
hour=item_conf["hour"],
day_of_week=item_conf["day_of_week"],
),
}
}
schedule_dict.update(to_add)
)
return schedule_dict