mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 11:12:15 +03:00
updated task manager added function for checking scheduler jobs
This commit is contained in:
parent
e35f538387
commit
a68ea26f79
4 changed files with 34 additions and 6 deletions
|
@ -22,6 +22,7 @@ class Scope(object):
|
|||
self.executionManager = None
|
||||
self.dbService = None
|
||||
self.messager = None
|
||||
self.scheduler = None
|
||||
|
||||
@staticmethod
|
||||
def getInstance():
|
||||
|
@ -106,3 +107,9 @@ class Scope(object):
|
|||
|
||||
def setMessager(self, messager):
|
||||
self.messager = messager
|
||||
|
||||
def set_scheduler(self, scheduler):
|
||||
self.scheduler = scheduler
|
||||
|
||||
def get_scheduler(self):
|
||||
return self.scheduler
|
|
@ -27,6 +27,16 @@ class CustomScheduler(BaseScheduler):
|
|||
def add_job(self, job):
|
||||
self.events.append(job)
|
||||
|
||||
def save_and_add_job(self, task):
|
||||
self.scheduledb.save(task)
|
||||
self.events.append(ScheduleTaskJob(task))
|
||||
|
||||
def remove_job(self,task):
|
||||
self.scheduledb.delete(task)
|
||||
for event in self.events:
|
||||
if event.task.id == task.id:
|
||||
self.events.remove(event)
|
||||
|
||||
def stop(self):
|
||||
self.keep_run = False
|
||||
|
||||
|
|
|
@ -23,10 +23,12 @@ class ScheduleTaskJob(object):
|
|||
def processTask(self):
|
||||
try:
|
||||
self.task_manager.addTask(self.task)
|
||||
if self.is_single_shot():
|
||||
Scope.getInstance().get_scheduler().remove_job(self.task)
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
|
||||
def parse_cron_str(self,cron_str):
|
||||
def parse_cron_str(self, cron_str):
|
||||
try:
|
||||
cron_exp_arr = cron_str.split(" ")
|
||||
cron_sj = []
|
||||
|
@ -66,6 +68,11 @@ class ScheduleTaskJob(object):
|
|||
obj = set(obj)
|
||||
return obj
|
||||
|
||||
def is_single_shot(self):
|
||||
if '*' in self.task.cron_str:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def matchtime(self, t):
|
||||
"""Return True if this event should trigger at the specified datetime"""
|
||||
|
|
|
@ -15,14 +15,18 @@ class TaskManager(object):
|
|||
self.pluginManager = scope.getPluginManager()
|
||||
self.logger = scope.getLogger()
|
||||
self.db_service = scope.getDbService()
|
||||
self.scheduler = scope.get_scheduler()
|
||||
|
||||
def addTask(self, task):
|
||||
try:
|
||||
self.logger.debug('Adding task ... ')
|
||||
self.saveTask(task)
|
||||
self.logger.info('Task saved ')
|
||||
# TODO send task received message
|
||||
self.pluginManager.processTask(task)
|
||||
if not task.cron_str == None or task.cron_str == '':
|
||||
self.logger.debug('Adding task ... ')
|
||||
self.saveTask(task)
|
||||
self.logger.info('Task saved ')
|
||||
# TODO send task received message
|
||||
self.pluginManager.processTask(task)
|
||||
else:
|
||||
self.scheduler.save_and_add_job(task)
|
||||
|
||||
except Exception as e:
|
||||
# TODO error log here
|
||||
|
|
Loading…
Reference in a new issue