From b86aaf70164023615c3426dadde89ab6f1783ccf Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Sun, 22 Sep 2024 11:57:44 +0100 Subject: [PATCH] Add cadence values to the matchy tasks cadence - Run this task every "x" weeks cadence - Unix seconds timestamp for the start of this cadence --- matchy/state.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/matchy/state.py b/matchy/state.py index d498af6..9fd16bb 100644 --- a/matchy/state.py +++ b/matchy/state.py @@ -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), } ] }