From 04bc95c8a1ce6a4b33a8e1880cd2cbe61a7cf9ae Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 11 Feb 2020 10:42:37 +0000 Subject: [PATCH] add more cron timestamp fields, allow callbacks to runtime provide schedules --- src/core_modules/cron.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core_modules/cron.py b/src/core_modules/cron.py index 8c619e59..e0c0ceb3 100644 --- a/src/core_modules/cron.py +++ b/src/core_modules/cron.py @@ -21,14 +21,20 @@ class Module(ModuleManager.BaseModule): now = datetime.datetime.utcnow().replace(second=0, microsecond=0) timer.redo() - timestamp = [now.minute, now.hour] + timestamp = [now.minute, now.hour, now.day, now.month, + now.isoweekday()%7] events = self.events.on("cron") - event = events.make_event() - for cron in events.get_hooks(): - schedule = cron.get_kwarg("schedule").split(" ") + def _check(schedule): + return self._schedule_match(timestamp, schedule.split(" ")) + event = events.make_event(schedule=_check) - if self._schedule_match(timestamp, schedule): + + for cron in events.get_hooks(): + schedule = cron.get_kwarg("schedule", None) + if schedule and not _check(schedule): + continue + else: cron.call(event) def _schedule_match(self, timestamp, schedule):