From a341deefeee97e918367053e685af0b14f4bdd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0smail=20Ba=C5=9Faran?= Date: Tue, 5 Apr 2016 19:12:40 +0300 Subject: [PATCH] added remove schedule job via task id method --- opt/ahenk/ahenkd.py | 1 + opt/ahenk/base/scheduler/custom/custom_scheduler.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/opt/ahenk/ahenkd.py b/opt/ahenk/ahenkd.py index 6fed261..355048a 100755 --- a/opt/ahenk/ahenkd.py +++ b/opt/ahenk/ahenkd.py @@ -55,6 +55,7 @@ class AhenkDeamon(BaseDaemon): sc_thread = threading.Thread(target=scheduler_ins.run) sc_thread.setDaemon(True) sc_thread.start() + return scheduler_ins def init_event_manager(self): eventManager = EventManager() diff --git a/opt/ahenk/base/scheduler/custom/custom_scheduler.py b/opt/ahenk/base/scheduler/custom/custom_scheduler.py index c14ce18..f911d13 100644 --- a/opt/ahenk/base/scheduler/custom/custom_scheduler.py +++ b/opt/ahenk/base/scheduler/custom/custom_scheduler.py @@ -31,15 +31,24 @@ class CustomScheduler(BaseScheduler): self.scheduledb.save(task) self.events.append(ScheduleTaskJob(task)) - def remove_job(self,task): - self.scheduledb.delete(task) + def remove_job(self, task): for event in self.events: if event.task.id == task.id: + self.scheduledb.delete(task) + self.events.remove(event) + + def remove_job_via_task_id(self,task_id): + for event in self.events: + if event.task.id == task_id: + self.scheduledb.delete(event.task) self.events.remove(event) def stop(self): self.keep_run = False + def list_schedule_tasks(self): + return self.scheduledb.load() + def run(self): t = datetime(*datetime.now().timetuple()[:5]) while 1 and self.keep_run: