|
@@ -3,6 +3,7 @@ from crontab import CronSlices
|
|
|
|
|
|
from core.ConfigurationManager.BrainLoader import BrainLoader
|
|
|
from core.Models import Event
|
|
|
+import logging
|
|
|
|
|
|
|
|
|
class InvalidCrontabPeriod(Exception):
|
|
@@ -19,16 +20,20 @@ class CrontabManager:
|
|
|
self.brain = BrainLoader(filename=brain_file).get_brain()
|
|
|
|
|
|
def load_events_in_crontab(self):
|
|
|
+ """
|
|
|
+ Remove all line in crontab with the CRONTAB_COMMENT
|
|
|
+ Then add back line from event in the brain.yml
|
|
|
+ :return:
|
|
|
+ """
|
|
|
|
|
|
self._remove_all_jarvis_job()
|
|
|
-
|
|
|
+
|
|
|
for synapse in self.brain.synapes:
|
|
|
for signal in synapse.signals:
|
|
|
- print signal
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
if type(signal) == Event:
|
|
|
- print "is event"
|
|
|
-
|
|
|
+
|
|
|
self._add_event(period_string=signal.period, event_id=signal.identifier)
|
|
|
|
|
|
def _add_event(self, period_string, event_id):
|
|
@@ -52,6 +57,14 @@ class CrontabManager:
|
|
|
"""
|
|
|
iter = self.my_user_cron.find_comment(CRONTAB_COMMENT)
|
|
|
for job in iter:
|
|
|
+ logging.debug("remove job %s from crontab" % job)
|
|
|
self.my_user_cron.remove(job)
|
|
|
|
|
|
- self.my_user_cron.write()
|
|
|
+ self.my_user_cron.write()
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ new_iter = self.my_user_cron.find_comment(CRONTAB_COMMENT)
|
|
|
+ sum_job = sum(1 for _ in new_iter)
|
|
|
+ while sum_job > 0:
|
|
|
+ self._remove_all_jarvis_job()
|