diff --git a/opt/ahenk/base/plugin/Plugin.py b/opt/ahenk/base/plugin/Plugin.py index 99387da..f942e8d 100644 --- a/opt/ahenk/base/plugin/Plugin.py +++ b/opt/ahenk/base/plugin/Plugin.py @@ -16,11 +16,12 @@ class Plugin(threading.Thread): def run(): try: task=self.InQueue.get() - command = self.pluginManager.findCommand(task.getCommandId()) + command = self.pluginManager.findCommand(self.getName(),task.getCommandId()) command.handle_task(task) # TODO add result to response queue except Exception as e: + #TODO error log here print("exception occured when executing plugin") def getName(self): diff --git a/opt/ahenk/base/plugin/PluginManager.py b/opt/ahenk/base/plugin/PluginManager.py index 2e35deb..caee36c 100644 --- a/opt/ahenk/base/plugin/PluginManager.py +++ b/opt/ahenk/base/plugin/PluginManager.py @@ -23,7 +23,7 @@ class PluginManager(object): for pname in possibleplugins: location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname) if not os.path.isdir(location) or not self.configManager.get("PLUGIN", "mainModuleName") + ".py" in os.listdir(location): - #TODO debug log here + self.logger.debug('It is not a plugin location - %s - ',location) continue try: self.loadSinglePlugin(pname) @@ -39,10 +39,34 @@ class PluginManager(object): self.plugins.append(plugin) def findCommand(self,pluginName,commandId): - location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pname) + location = os.path.join(self.configManager.get("PLUGIN", "pluginFolderPath"), pluginName) if os.path.dir(location) and commandId + ".py" in os.listdir(location): info = imp.find_module(commandId, [location]) return imp.load_module(commandId, *info) else: self.logger.warning('Command id - %s - not found',commandId) return None + + def processTask(self,task): + try: + if task.getPluginId().lower() in self.pluginQueueDict : + self.pluginQueueDict[task.getPluginId().lower()].put(task,task.priority) + except Exception as e: + # TODO error log here + # TODO update task - status to not found command + + def reloadPlugins(self): + # Not implemented yet + pass + + def checkPluginExists(self,pluginName): + # Not implemented yet + pass + + def reloadSinglePlugin(self,pluginName): + # Not implemented yet + pass + + def checkCommandExist(self,pluginName,commandId): + # Not implemented yet + pass diff --git a/opt/ahenk/base/task/TaskManager.py b/opt/ahenk/base/task/TaskManager.py index e011f1b..874ce07 100644 --- a/opt/ahenk/base/task/TaskManager.py +++ b/opt/ahenk/base/task/TaskManager.py @@ -1,9 +1,37 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- # Author: İsmail BAŞARAN +from base.Scope import Scope class TaskManager(object): """docstring for TaskManager""" def __init__(self): super(TaskManager, self).__init__() - + scope = Scope.getInstance() + self.pluginManager = scope.getPluginManager() + self.logger= scope.getLogger() + + def addTask(self,task): + try: + # TODO add log + # TODO save task to database + # TODO send task received message + self.pluginManager.processTask(task) + except Exception as e: + # TODO error log here + + 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 updateTask(self,task): + # TODO not implemented yet + # This is updates task status processing - processed ... + pass + + def deleteTask(self,task): + # TODO not implemented yet + # remove task if it is processed + pass