mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2025-01-11 19:12:16 +03:00
message response queue and added classes to ahenkd service
This commit is contained in:
parent
8939ac4a36
commit
3956c0539b
4 changed files with 46 additions and 14 deletions
|
@ -7,10 +7,12 @@ from base.deamon.BaseDeamon import BaseDaemon
|
||||||
from base.logger.AhenkLogger import Logger
|
from base.logger.AhenkLogger import Logger
|
||||||
from base.Scope import Scope
|
from base.Scope import Scope
|
||||||
from base.messaging.Messaging import Messaging
|
from base.messaging.Messaging import Messaging
|
||||||
|
from base.messaging.MessageResponseQueue import MessageResponseQueue
|
||||||
|
from base.plugin.PluginManager import PluginManager
|
||||||
|
from base.task.TaskManager import TaskManager
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import sys,logging
|
import sys,logging,queue,time
|
||||||
import time
|
|
||||||
|
|
||||||
|
|
||||||
class AhenkDeamon(BaseDaemon):
|
class AhenkDeamon(BaseDaemon):
|
||||||
|
@ -29,11 +31,21 @@ class AhenkDeamon(BaseDaemon):
|
||||||
config = configManager.read()
|
config = configManager.read()
|
||||||
globalscope.setConfigurationManager(config)
|
globalscope.setConfigurationManager(config)
|
||||||
|
|
||||||
|
# Logger must be second
|
||||||
logger = Logger()
|
logger = Logger()
|
||||||
logger.info("obaraaa")
|
logger.info("this is info log")
|
||||||
globalscope.setLogger(logger)
|
globalscope.setLogger(logger)
|
||||||
|
|
||||||
|
pluginManager = PluginManager()
|
||||||
|
pluginManager.loadPlugins()
|
||||||
|
globalscope.setPluginManager(pluginManager)
|
||||||
|
|
||||||
|
taskManger = TaskManager()
|
||||||
|
globalscope.setTaskManager(taskManger)
|
||||||
|
|
||||||
|
# add services after this line
|
||||||
|
|
||||||
|
"""
|
||||||
xmpp = Messaging()
|
xmpp = Messaging()
|
||||||
print("xmpp is created")
|
print("xmpp is created")
|
||||||
p = Process(target=xmpp.connect_to_server)
|
p = Process(target=xmpp.connect_to_server)
|
||||||
|
@ -44,7 +56,16 @@ class AhenkDeamon(BaseDaemon):
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
print("sleep is over ")
|
print("sleep is over ")
|
||||||
xmpp.send_direct_message("asdasdas")# not working ->connection error
|
xmpp.send_direct_message("asdasdas")# not working ->connection error
|
||||||
|
"""
|
||||||
|
|
||||||
|
"""
|
||||||
|
this is must be created after message services
|
||||||
|
responseQueue = queue.Queue()
|
||||||
|
messageResponseQueue = MessageResponseQueue(responseQueue)
|
||||||
|
messageResponseQueue.setDaemon(True)
|
||||||
|
messageResponseQueue.start()
|
||||||
|
globalscope.setResponseQueue(responseQueue)
|
||||||
|
"""
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Scope(object):
|
||||||
self.logger=None
|
self.logger=None
|
||||||
self.pluginManager=None
|
self.pluginManager=None
|
||||||
self.taskManager=None
|
self.taskManager=None
|
||||||
|
self.responseQueue=None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getInstance():
|
def getInstance():
|
||||||
|
@ -64,3 +65,9 @@ class Scope(object):
|
||||||
|
|
||||||
def setTaskManager(self,taskManager):
|
def setTaskManager(self,taskManager):
|
||||||
self.taskManager = taskManager
|
self.taskManager = taskManager
|
||||||
|
|
||||||
|
def getResponseQueue(self):
|
||||||
|
return self.responseQueue
|
||||||
|
|
||||||
|
def setResponseQueue(self,responseQueue):
|
||||||
|
self.responseQueue=responseQueue
|
||||||
|
|
|
@ -24,6 +24,6 @@ class MessageResponseQueue(threading.Thread):
|
||||||
print(item)
|
print(item)
|
||||||
# Call message manager for response
|
# Call message manager for response
|
||||||
self.messageManager.sendResponse(responseMessage)
|
self.messageManager.sendResponse(responseMessage)
|
||||||
self.outQueue.task_done()
|
#self.outQueue.task_done()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -18,6 +18,7 @@ class PluginManager(object):
|
||||||
self.logger = scope.getLogger()
|
self.logger = scope.getLogger()
|
||||||
|
|
||||||
def loadPlugins(self):
|
def loadPlugins(self):
|
||||||
|
print("loading")
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||||
for pname in possibleplugins:
|
for pname in possibleplugins:
|
||||||
|
@ -72,3 +73,6 @@ class PluginManager(object):
|
||||||
def checkCommandExist(self,pluginName,commandId):
|
def checkCommandExist(self,pluginName,commandId):
|
||||||
# Not implemented yet
|
# Not implemented yet
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def printQueueSize(self):
|
||||||
|
print("size " + str(len(self.pluginQueueDict)))
|
||||||
|
|
Loading…
Reference in a new issue