Add cadence values to the matchy tasks

cadence - Run this task every "x" weeks
cadence - Unix seconds timestamp for the start of this cadence
This commit is contained in:
Marc Di Luzio 2024-09-22 11:57:44 +01:00
parent caadca885c
commit b86aaf7016

View file

@ -16,7 +16,7 @@ logger = logging.getLogger("state")
logger.setLevel(logging.INFO)
# Warning: Changing any of the below needs proper thought to ensure backwards compatibility
_VERSION = 4
_VERSION = 5
def _migrate_to_v1(d: dict):
@ -64,12 +64,24 @@ def _migrate_to_v4(d: dict):
del d[_Key._HISTORY]
def _migrate_to_v5(d: dict):
"""v5 added weekly cadence"""
tasks = d.get(_Key.TASKS, {})
for tasks in tasks.values():
match_tasks = tasks.get(_Key.MATCH_TASKS, [])
for match in match_tasks:
# All previous matches were every week starting from now
match[_Key.CADENCE] = 1
match[_Key.CADENCE_START] = int(datetime.now().timestamp())
# Set of migration functions to apply
_MIGRATIONS = [
_migrate_to_v1,
_migrate_to_v2,
_migrate_to_v3,
_migrate_to_v4,
_migrate_to_v5
]
@ -94,6 +106,8 @@ class _Key(str):
MEMBERS_MIN = "members_min"
WEEKDAY = "weekdays"
HOUR = "hours"
CADENCE = "cadence"
CADENCE_START = "CADENCE_START"
# Unused
_MATCHEES = "matchees"
@ -139,6 +153,8 @@ _SCHEMA = Schema(
_Key.MEMBERS_MIN: Use(int),
_Key.WEEKDAY: Use(int),
_Key.HOUR: Use(int),
_Key.CADENCE: Use(int),
_Key.CADENCE_START: Use(int),
}
]
}