mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-11 00:02:16 +03:00
Storing tasks in database
This commit is contained in:
parent
613cb68df3
commit
2bcf476aa8
1 changed files with 15 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||||
|
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
from base.model.MessageFactory import MessageFactory
|
from base.model.MessageFactory import MessageFactory
|
||||||
from base.model.enum.MessageType import MessageType
|
from base.model.enum.MessageType import MessageType
|
||||||
|
@ -19,33 +20,34 @@ class TaskManager(object):
|
||||||
|
|
||||||
def addTask(self, task):
|
def addTask(self, task):
|
||||||
try:
|
try:
|
||||||
|
self.saveTask(task)
|
||||||
if task.get_cron_str() == None or task.get_cron_str() == '':
|
if task.get_cron_str() == None or task.get_cron_str() == '':
|
||||||
self.logger.debug('Adding task ... ')
|
self.logger.debug('[TaskManager] Adding task ... ')
|
||||||
#self.saveTask(task)
|
|
||||||
self.logger.info('Task saved ')
|
|
||||||
# TODO send task received message
|
|
||||||
self.pluginManager.processTask(task)
|
self.pluginManager.processTask(task)
|
||||||
else:
|
else:
|
||||||
self.scheduler.save_and_add_job(task)
|
self.scheduler.save_and_add_job(task)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO error log here
|
self.logger.debug('[TaskManager] Exception occured when adding task. Error Message: {}'.format(str(e)))
|
||||||
self.logger.debug('Exception occured when adding task ' + str(e))
|
|
||||||
pass
|
|
||||||
|
|
||||||
def addPolicy(self, policy):
|
def addPolicy(self, policy):
|
||||||
try:
|
try:
|
||||||
self.pluginManager.processPolicy(policy)
|
self.pluginManager.processPolicy(policy)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("Exception occured when adding policy. Error Message: {}".format(str(e)))
|
self.logger.error("[TaskManager] Exception occured when adding policy. Error Message: {}".format(str(e)))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def saveTask(self, task):
|
def saveTask(self, task):
|
||||||
|
try:
|
||||||
cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin']
|
task_cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin','cron_expr']
|
||||||
values = [str(task.get_id()), str(task.get_create_date()), str(task.get_modify_date()), str(task.get_command_cls_id()), str(task.get_parameter_map()), str(task.get_deleted()), task.plugin.to_string()]
|
plu_cols = ['active', 'create_date', 'deleted', 'description', 'machine_oriented', 'modify_date', 'name', 'policy_plugin', 'user_oriented', 'version','task_plugin','x_based']
|
||||||
self.db_service.update('task', cols, values, None)
|
plugin_args = [str(task.get_plugin().get_active()), str(task.get_plugin().get_create_date()), str(task.get_plugin().get_deleted()), str(task.get_plugin().get_description()), str(task.get_plugin().get_machine_oriented()), str(task.get_plugin().get_modify_date()), str(task.get_plugin().get_name()), str(task.get_plugin().get_policy_plugin()), str(task.get_plugin().get_user_oriented()), str(task.get_plugin().get_version()), str(task.get_plugin().get_task_plugin()), str(task.get_plugin().get_x_based())]
|
||||||
self.logger.debug('[TaskManager] Task has been saved to database (Task id:' + task.id + ')')
|
plugin_id = self.db_service.update('plugin', plu_cols, plugin_args)
|
||||||
|
values = [str(task.get_id()), str(task.get_create_date()), str(task.get_modify_date()), str(task.get_command_cls_id()), str(task.get_parameter_map()), str(task.get_deleted()), str(plugin_id),str(task.get_cron_str())]
|
||||||
|
self.db_service.update('task', task_cols, values, None)
|
||||||
|
# self.logger.debug('[TaskManager] Task has been saved to database (Task id:' + task.get_id() + ')')
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
def updateTask(self, task):
|
def updateTask(self, task):
|
||||||
# TODO not implemented yet
|
# TODO not implemented yet
|
||||||
|
|
Loading…
Reference in a new issue