add more cron timestamp fields, allow callbacks to runtime provide schedules

This commit is contained in:
jesopo 2020-02-11 10:42:37 +00:00
parent f1b15ea7b6
commit 04bc95c8a1

View file

@ -21,14 +21,20 @@ class Module(ModuleManager.BaseModule):
now = datetime.datetime.utcnow().replace(second=0, microsecond=0) now = datetime.datetime.utcnow().replace(second=0, microsecond=0)
timer.redo() timer.redo()
timestamp = [now.minute, now.hour] timestamp = [now.minute, now.hour, now.day, now.month,
now.isoweekday()%7]
events = self.events.on("cron") events = self.events.on("cron")
event = events.make_event() def _check(schedule):
for cron in events.get_hooks(): return self._schedule_match(timestamp, schedule.split(" "))
schedule = cron.get_kwarg("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) cron.call(event)
def _schedule_match(self, timestamp, schedule): def _schedule_match(self, timestamp, schedule):