mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 10:52:17 +03:00
removing executed scheduled task was removed
This commit is contained in:
parent
aa2023643f
commit
683c5f97b8
1 changed files with 17 additions and 11 deletions
|
@ -6,10 +6,10 @@ from base.scheduler.custom.all_match import AllMatch
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
|
|
||||||
|
|
||||||
# TODO Need logs
|
|
||||||
class ScheduleTaskJob(object):
|
class ScheduleTaskJob(object):
|
||||||
def __init__(self, task):
|
def __init__(self, task):
|
||||||
scope = Scope.getInstance()
|
scope = Scope.getInstance()
|
||||||
|
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.getLogger()
|
||||||
self.task_manager = scope.getTaskManager()
|
self.task_manager = scope.getTaskManager()
|
||||||
self.plugin_manager = scope.getPluginManager()
|
self.plugin_manager = scope.getPluginManager()
|
||||||
|
@ -25,17 +25,21 @@ class ScheduleTaskJob(object):
|
||||||
self.action = self.process_task
|
self.action = self.process_task
|
||||||
self.logger.debug('[ScheduleTaskJob] Instance created.')
|
self.logger.debug('[ScheduleTaskJob] Instance created.')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ScheduleTaskJob] A problem occurred while creating instance of ScheduleTaskJob. Error Message : {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[ScheduleTaskJob] A problem occurred while creating instance of ScheduleTaskJob. Error Message : {0}'.format(
|
||||||
|
str(e)))
|
||||||
|
|
||||||
def process_task(self):
|
def process_task(self):
|
||||||
try:
|
try:
|
||||||
self.logger.debug('[ScheduleTaskJob] Running scheduled task now...')
|
self.logger.debug('[ScheduleTaskJob] Running scheduled task now...')
|
||||||
self.plugin_manager.process_task(self.task)
|
self.plugin_manager.process_task(self.task)
|
||||||
self.logger.debug('[ScheduleTaskJob] Scheduled Task was executed.')
|
self.logger.debug('[ScheduleTaskJob] Scheduled Task was executed.')
|
||||||
if self.is_single_shot():
|
# There is no any single shot task
|
||||||
Scope.getInstance().get_scheduler().remove_job(self.task.get_id())
|
# if self.is_single_shot():
|
||||||
|
# Scope.getInstance().get_scheduler().remove_job(self.task.get_id())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ScheduleTaskJob] A problem occurred while running scheduled task. Error Message: {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[ScheduleTaskJob] A problem occurred while running scheduled task. Error Message: {0}'.format(str(e)))
|
||||||
|
|
||||||
def parse_cron_str(self, cron_str):
|
def parse_cron_str(self, cron_str):
|
||||||
self.logger.debug('[ScheduleTaskJob] Parsing cron string...')
|
self.logger.debug('[ScheduleTaskJob] Parsing cron string...')
|
||||||
|
@ -69,7 +73,8 @@ class ScheduleTaskJob(object):
|
||||||
count = count + 1
|
count = count + 1
|
||||||
return cron_sj
|
return cron_sj
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error('[ScheduleTaskJob] A problem occurred while parsing cron expression. Error Message: {}'.format(str(e)))
|
self.logger.error(
|
||||||
|
'[ScheduleTaskJob] A problem occurred while parsing cron expression. Error Message: {}'.format(str(e)))
|
||||||
|
|
||||||
def conv_to_set(self, obj):
|
def conv_to_set(self, obj):
|
||||||
self.logger.debug('[ScheduleTaskJob] Converting {} to set'.format(str(obj)))
|
self.logger.debug('[ScheduleTaskJob] Converting {} to set'.format(str(obj)))
|
||||||
|
@ -81,14 +86,15 @@ class ScheduleTaskJob(object):
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def is_single_shot(self):
|
# def is_single_shot(self):
|
||||||
if '*' in self.task.cron_str:
|
# if '*' in self.task.cron_str:
|
||||||
return True
|
# return True
|
||||||
else:
|
# else:
|
||||||
return False
|
# return False
|
||||||
|
|
||||||
def matchtime(self, t):
|
def matchtime(self, t):
|
||||||
"""Return True if this event should trigger at the specified datetime"""
|
"""Return True if this event should trigger at the specified datetime"""
|
||||||
|
|
||||||
return ((t.minute in self.mins) and
|
return ((t.minute in self.mins) and
|
||||||
(t.hour in self.hours) and
|
(t.hour in self.hours) and
|
||||||
(t.day in self.days) and
|
(t.day in self.days) and
|
||||||
|
|
Loading…
Reference in a new issue