mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-25 22:52:24 +03:00
receiving task and save to DB
This commit is contained in:
parent
171b0320ee
commit
c003ba5305
4 changed files with 55 additions and 23 deletions
|
@ -17,10 +17,8 @@ class AhenkDbService(object):
|
|||
self.connection=None
|
||||
self.cursor = None
|
||||
|
||||
|
||||
|
||||
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('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'])
|
||||
|
|
|
@ -83,8 +83,9 @@ class ExecutionManager(object):
|
|||
|
||||
def execute_task(self,arg):
|
||||
self.logger.debug('[ExecutionManager] Adding new task...')
|
||||
task = Task(arg)
|
||||
task = Task(json.loads(arg))
|
||||
self.task_manager.addTask(task)
|
||||
self.logger.debug('[ExecutionManager] Task added')
|
||||
|
||||
def move_file(self,arg):
|
||||
default_file_path=self.config_manager.get('CONNECTION', 'receiveFileParam')
|
||||
|
|
|
@ -1,18 +1,49 @@
|
|||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# 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
|
||||
|
||||
class Task(object):
|
||||
"""docstring for Task"""
|
||||
def __init__(self,message):
|
||||
self.payload = json.loads(message)
|
||||
self.request = self.payload['request']
|
||||
self.task = message['task']
|
||||
|
||||
@property
|
||||
def task(self):
|
||||
self.request['task']
|
||||
def id(self):
|
||||
return self.task['id']
|
||||
|
||||
@property
|
||||
def timestamp(self):
|
||||
self.request['timestamp']
|
||||
def create_date(self):
|
||||
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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,18 +5,20 @@ from base.Scope import Scope
|
|||
from base.model.MessageFactory import MessageFactory
|
||||
from base.model.MessageType import MessageType
|
||||
|
||||
|
||||
class TaskManager(object):
|
||||
"""docstring for TaskManager"""
|
||||
|
||||
def __init__(self):
|
||||
super(TaskManager, self).__init__()
|
||||
scope = Scope.getInstance()
|
||||
self.pluginManager = scope.getPluginManager()
|
||||
self.logger= scope.getLogger()
|
||||
self.dbService = scope.getDbService()
|
||||
self.logger = scope.getLogger()
|
||||
self.db_service = scope.getDbService()
|
||||
|
||||
def addTask(self,task):
|
||||
def addTask(self, task):
|
||||
try:
|
||||
self.logger.debug('Adding task ... ' + str(task.plugin_ame) + ' - ' + str(task.command_id))
|
||||
self.logger.debug('Adding task ... ')
|
||||
self.saveTask(task)
|
||||
# TODO send task received message
|
||||
self.pluginManager.processTask(task)
|
||||
|
@ -24,26 +26,26 @@ class TaskManager(object):
|
|||
# TODO error log here
|
||||
pass
|
||||
|
||||
def saveTask(self,task):
|
||||
# TODO not implemented yet
|
||||
# task reveiced to ahenk save to db firstly.
|
||||
# if user close before processing task you can load from db for process
|
||||
pass
|
||||
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 + ')')
|
||||
|
||||
def updateTask(self,task):
|
||||
def updateTask(self, task):
|
||||
# TODO not implemented yet
|
||||
# This is updates task status processing - processed ...
|
||||
pass
|
||||
|
||||
def deleteTask(self,task):
|
||||
def deleteTask(self, task):
|
||||
# TODO not implemented yet
|
||||
# remove task if it is processed
|
||||
pass
|
||||
|
||||
def sendMessage(self,type,message):
|
||||
def sendMessage(self, type, message):
|
||||
# TODO not implemented yet
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(MessageFactory.createMessage(MessageType.TASK_PROCESSING,"my message"))
|
||||
print(MessageFactory.createMessage(MessageType.TASK_PROCESSING, "my message"))
|
||||
|
|
Loading…
Reference in a new issue