created message type

This commit is contained in:
İsmail Başaran 2016-03-14 10:55:28 +02:00
parent 077b57a095
commit 240ab35292
7 changed files with 57 additions and 6 deletions

View file

@ -11,6 +11,7 @@ This README would normally document whatever steps are necessary to get your app
### How can I build and create deb file ? ###
Clone project and go to ahenk project folder, run command below
$ dpkg-buildpackage
### How do I get set up? ###

View file

@ -19,6 +19,7 @@ class Scope(object):
self.responseQueue=None
self.registration=None
self.eventManager=None
self.dbService=None
@staticmethod
@ -86,3 +87,9 @@ class Scope(object):
def setEventManager(self,eventManager):
self.eventManager=eventManager
def getDbService(self):
return self.dbService
def serDbService(self,dbService):
self.dbService = dbService

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
import sys
sys.path.append('../..')
import logging
import logging.config
from base.Scope import Scope

View file

@ -0,0 +1,16 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.model.MessageType import MessageType
class MessageFactory(object):
def createMessage(self,type,message):
if type == MessageType.TASK_RECEIVED:
return "Message receivden response"
elif type == MessageType.TASK_PROCESSING:
return "Message processing response"
else
return None
createMessage = staticmethod(createMessage)

View file

@ -0,0 +1,13 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from enum import Enum
class MessageType(Enum):
TASK_RECEIVED="TASK_RECEIVED"
TASK_PROCESSING="TASK_PROCESSING"
TASK_PROCESSED="TASK_PROCESSED"
TASK_ERROR="TASK_ERROR"
TASK_WARNING="TASK_WARNING"
POLICY_RECEIVED="POLICY_RECEIVED"
POLICY_PROCESSED="POLICY_PROCESSED"

View file

@ -10,11 +10,15 @@ class Task(object):
self.request = self.payload[u'request']
@property
def getPluginName(self):
def task_id(self):
self.request[u'id']
@property
def plugin_name(self):
self.request[u'pluginName']
@property
def getCommandId(self):
def command_id(self):
self.request[u'commandId']
@property
@ -22,5 +26,5 @@ class Task(object):
self.request[u'parameterMap']
@property
def pluginVersion(self):
def plugin_version(self):
self.request[u'pluginVersion']

View file

@ -2,6 +2,8 @@
# -*- coding: utf-8 -*-
# Author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
from base.Scope import Scope
from base.model.MessageFactory import MessageFactory
from base.model.MessageType import MessageType
class TaskManager(object):
"""docstring for TaskManager"""
@ -10,11 +12,12 @@ class TaskManager(object):
scope = Scope.getInstance()
self.pluginManager = scope.getPluginManager()
self.logger= scope.getLogger()
self.dbService = scope.getDbService()
def addTask(self,task):
try:
# TODO add log
# TODO save task to database
self.logger.debug('Adding task ... ' + str(task.plugin_ame) + ' - ' + str(task.command_id))
self.saveTask(task)
# TODO send task received message
self.pluginManager.processTask(task)
except Exception as e:
@ -36,3 +39,11 @@ class TaskManager(object):
# TODO not implemented yet
# remove task if it is processed
pass
def sendMessage(self,type,message):
# TODO not implemented yet
pass
if __name__ == '__main__':
print(MessageFactory.createMessage(MessageType.TASK_PROCESSING,"my message"))