aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-12-11 15:43:17 +0000
committerGravatar jesopo2019-12-11 15:43:17 +0000
commit60db9ff389a3f4745a24d7b79d57c92b4ba38769 (patch)
tree699c4aa4998d750dac0720d6e41139354977f2a5 /src
parentsend.stdout should default to thinking it is in-channel (diff)
signature
first draft on cron module
Diffstat (limited to 'src')
-rw-r--r--src/core_modules/cron.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/core_modules/cron.py b/src/core_modules/cron.py
new file mode 100644
index 00000000..9ad6cb07
--- /dev/null
+++ b/src/core_modules/cron.py
@@ -0,0 +1,37 @@
+import datetime, time
+from src import ModuleManager, utils
+
+class Module(ModuleManager.BaseModule):
+ def on_load(self):
+ now = datetime.datetime.utcnow()
+ next_minute = now.replace(minute=now.minute+1, second=0, microsecond=0)
+ until = time.time()+(next_minute-now).total_seconds()
+ self.timers.add("cron", self._minute, 60, until)
+
+ def _minute(self, timer):
+ now = datetime.datetime.utcnow().replace(second=0, microsecond=0)
+ timer.redo()
+
+ current_schedule = [now.minute, now.hour]
+
+ events = self.events.on("cron")
+ for cron in events.get_hooks():
+ schedule = cron.get_kwarg("schedule").split(" ")
+
+ due = True
+ for i, schedule_part in enumerate(schedule):
+ current_part = current_schedule[i]
+ if schedule_part.startswith("*/"):
+ schedule_step = int(schedule_part.split("*/", 1)[1])
+ if (current_part%schedule_step) == 0:
+ continue
+ elif schedule_part == "*":
+ continue
+ elif int(current_part) == schedule_part:
+ continue
+
+ due = False
+ break
+
+ if due:
+ cron.call(events.make_event())