Ahenk/opt/ahenk/base/task/TaskManager.py

54 lines
1.9 KiB
Python
Raw Normal View History

2016-02-29 17:13:39 +02:00
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.Scope import Scope
2016-03-14 10:55:28 +02:00
from base.model.MessageFactory import MessageFactory
from base.model.MessageType import MessageType
2016-02-29 17:13:39 +02:00
2016-03-21 12:02:15 +02:00
2016-02-29 17:13:39 +02:00
class TaskManager(object):
"""docstring for TaskManager"""
2016-03-21 12:02:15 +02:00
2016-02-29 17:13:39 +02:00
def __init__(self):
# super(TaskManager, self).__init__()
scope = Scope.getInstance()
self.pluginManager = scope.getPluginManager()
2016-03-21 12:02:15 +02:00
self.logger = scope.getLogger()
self.db_service = scope.getDbService()
2016-03-21 12:02:15 +02:00
def addTask(self, task):
try:
2016-03-21 12:02:15 +02:00
self.logger.debug('Adding task ... ')
self.saveTask(task)
2016-03-23 10:04:31 +02:00
self.logger.info('Task saved ')
# TODO send task received message
self.pluginManager.processTask(task)
except Exception as e:
# TODO error log here
2016-03-23 10:04:31 +02:00
self.logger.debug('Exception occured when adding task ' + str(e))
2016-03-02 15:45:36 +02:00
pass
2016-03-21 12:02:15 +02:00
def saveTask(self, task):
cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin']
values = [str(task.id), str(task.create_date), str(task.modify_date), str(task.command_cls_id), str(task.parameter_map), str(task.deleted), task.plugin.to_string()]
self.db_service.update('task', cols, values, None)
self.logger.debug('[TaskManager] Task has been saved to database (Task id:' + task.id + ')')
2016-03-21 12:02:15 +02:00
def updateTask(self, task):
# TODO not implemented yet
# This is updates task status processing - processed ...
pass
2016-03-21 12:02:15 +02:00
def deleteTask(self, task):
# TODO not implemented yet
# remove task if it is processed
pass
2016-03-14 10:55:28 +02:00
2016-03-21 12:02:15 +02:00
def sendMessage(self, type, message):
2016-03-14 10:55:28 +02:00
# TODO not implemented yet
pass
if __name__ == '__main__':
2016-03-21 12:02:15 +02:00
print(MessageFactory.createMessage(MessageType.TASK_PROCESSING, "my message"))