receiving task and save to DB

This commit is contained in:
Volkan Şahin 2016-03-21 12:02:15 +02:00
parent 171b0320ee
commit c003ba5305
4 changed files with 55 additions and 23 deletions

View file

@ -17,10 +17,8 @@ class AhenkDbService(object):
self.connection=None self.connection=None
self.cursor = None self.cursor = None
def initialize_table(self): def initialize_table(self):
self.check_and_create_table('task',['task TEXT','timestamp TEXT']) self.check_and_create_table('task',['id INTEGER','create_date TEXT','modify_date TEXT','command_cls_id TEXT','parameter_map BLOB','deleted INTEGER','plugin TEXT'])
self.check_and_create_table('policy',['id INTEGER PRIMARY KEY AUTOINCREMENT','type TEXT','version TEXT','name TEXT']) self.check_and_create_table('policy',['id INTEGER PRIMARY KEY AUTOINCREMENT','type TEXT','version TEXT','name TEXT'])
self.check_and_create_table('profile',['id INTEGER','create_date TEXT','label TEXT','description TEXT','overridable INTEGER','active INTEGER','deleted INTEGER','profile_data BLOB','modify_date TEXT']) self.check_and_create_table('profile',['id INTEGER','create_date TEXT','label TEXT','description TEXT','overridable INTEGER','active INTEGER','deleted INTEGER','profile_data BLOB','modify_date TEXT'])
self.check_and_create_table('plugin',['version TEXT','name TEXT','description TEXT']) self.check_and_create_table('plugin',['version TEXT','name TEXT','description TEXT'])

View file

@ -83,8 +83,9 @@ class ExecutionManager(object):
def execute_task(self,arg): def execute_task(self,arg):
self.logger.debug('[ExecutionManager] Adding new task...') self.logger.debug('[ExecutionManager] Adding new task...')
task = Task(arg) task = Task(json.loads(arg))
self.task_manager.addTask(task) self.task_manager.addTask(task)
self.logger.debug('[ExecutionManager] Task added')
def move_file(self,arg): def move_file(self,arg):
default_file_path=self.config_manager.get('CONNECTION', 'receiveFileParam') default_file_path=self.config_manager.get('CONNECTION', 'receiveFileParam')

View file

@ -1,18 +1,49 @@
#!/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>
# Author: Volkan Şahin <volkansah.in> <bm.volkansahin@gmail.com>
from base.model.Plugin import Plugin
import json import json
class Task(object): class Task(object):
"""docstring for Task""" """docstring for Task"""
def __init__(self,message): def __init__(self,message):
self.payload = json.loads(message) self.task = message['task']
self.request = self.payload['request']
@property @property
def task(self): def id(self):
self.request['task'] return self.task['id']
@property @property
def timestamp(self): def create_date(self):
self.request['timestamp'] return self.task['createdate']
@property
def modify_date(self):
return self.task['modifydate']
@property
def command_cls_id(self):
return self.task['commandclsid']
@property
def parameter_map(self):
return self.task['parametermap']
@property
def deleted(self):
return self.task['deleted']
@property
def plugin(self):
return Plugin(self.task['plugin'])
def to_string(self):
return str(self.task)
def to_json(self):
return json.load(self.task)

View file

@ -5,18 +5,20 @@ from base.Scope import Scope
from base.model.MessageFactory import MessageFactory from base.model.MessageFactory import MessageFactory
from base.model.MessageType import MessageType from base.model.MessageType import MessageType
class TaskManager(object): class TaskManager(object):
"""docstring for TaskManager""" """docstring for TaskManager"""
def __init__(self): def __init__(self):
super(TaskManager, self).__init__() super(TaskManager, self).__init__()
scope = Scope.getInstance() scope = Scope.getInstance()
self.pluginManager = scope.getPluginManager() self.pluginManager = scope.getPluginManager()
self.logger= scope.getLogger() self.logger = scope.getLogger()
self.dbService = scope.getDbService() self.db_service = scope.getDbService()
def addTask(self,task): def addTask(self, task):
try: try:
self.logger.debug('Adding task ... ' + str(task.plugin_ame) + ' - ' + str(task.command_id)) self.logger.debug('Adding task ... ')
self.saveTask(task) self.saveTask(task)
# TODO send task received message # TODO send task received message
self.pluginManager.processTask(task) self.pluginManager.processTask(task)
@ -24,26 +26,26 @@ class TaskManager(object):
# TODO error log here # TODO error log here
pass pass
def saveTask(self,task): def saveTask(self, task):
# TODO not implemented yet cols = ['id', 'create_date', 'modify_date', 'command_cls_id', 'parameter_map', 'deleted', 'plugin']
# task reveiced to ahenk save to db firstly. 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()]
# if user close before processing task you can load from db for process self.db_service.update('task', cols, values, None)
pass self.logger.debug('[TaskManager] Task has been saved to database (Task id:' + task.id + ')')
def updateTask(self,task): def updateTask(self, task):
# TODO not implemented yet # TODO not implemented yet
# This is updates task status processing - processed ... # This is updates task status processing - processed ...
pass pass
def deleteTask(self,task): def deleteTask(self, task):
# TODO not implemented yet # TODO not implemented yet
# remove task if it is processed # remove task if it is processed
pass pass
def sendMessage(self,type,message): def sendMessage(self, type, message):
# TODO not implemented yet # TODO not implemented yet
pass pass
if __name__ == '__main__': if __name__ == '__main__':
print(MessageFactory.createMessage(MessageType.TASK_PROCESSING,"my message")) print(MessageFactory.createMessage(MessageType.TASK_PROCESSING, "my message"))