mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 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.Scope import Scope
|
||||
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 threading import Thread
|
||||
import sys,logging
|
||||
import time
|
||||
import sys,logging,queue,time
|
||||
|
||||
|
||||
class AhenkDeamon(BaseDaemon):
|
||||
|
@ -29,22 +31,41 @@ class AhenkDeamon(BaseDaemon):
|
|||
config = configManager.read()
|
||||
globalscope.setConfigurationManager(config)
|
||||
|
||||
# Logger must be second
|
||||
logger = Logger()
|
||||
logger.info("obaraaa")
|
||||
logger.info("this is info log")
|
||||
globalscope.setLogger(logger)
|
||||
|
||||
pluginManager = PluginManager()
|
||||
pluginManager.loadPlugins()
|
||||
globalscope.setPluginManager(pluginManager)
|
||||
|
||||
xmpp = Messaging()
|
||||
print("xmpp is created")
|
||||
p = Process(target=xmpp.connect_to_server)
|
||||
print("Process thread starting")
|
||||
p.start()
|
||||
print("Process tread started")
|
||||
print("waiting 5sn ")
|
||||
time.sleep(5)
|
||||
print("sleep is over ")
|
||||
xmpp.send_direct_message("asdasdas")# not working ->connection error
|
||||
taskManger = TaskManager()
|
||||
globalscope.setTaskManager(taskManger)
|
||||
|
||||
# add services after this line
|
||||
|
||||
"""
|
||||
xmpp = Messaging()
|
||||
print("xmpp is created")
|
||||
p = Process(target=xmpp.connect_to_server)
|
||||
print("Process thread starting")
|
||||
p.start()
|
||||
print("Process tread started")
|
||||
print("waiting 5sn ")
|
||||
time.sleep(5)
|
||||
print("sleep is over ")
|
||||
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__':
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class Scope(object):
|
|||
self.logger=None
|
||||
self.pluginManager=None
|
||||
self.taskManager=None
|
||||
self.responseQueue=None
|
||||
|
||||
@staticmethod
|
||||
def getInstance():
|
||||
|
@ -64,3 +65,9 @@ class Scope(object):
|
|||
|
||||
def setTaskManager(self,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)
|
||||
# Call message manager for response
|
||||
self.messageManager.sendResponse(responseMessage)
|
||||
self.outQueue.task_done()
|
||||
#self.outQueue.task_done()
|
||||
except:
|
||||
pass
|
||||
|
|
|
@ -18,6 +18,7 @@ class PluginManager(object):
|
|||
self.logger = scope.getLogger()
|
||||
|
||||
def loadPlugins(self):
|
||||
print("loading")
|
||||
self.plugins = []
|
||||
possibleplugins = os.listdir(self.configManager.get("PLUGIN", "pluginFolderPath"))
|
||||
for pname in possibleplugins:
|
||||
|
@ -72,3 +73,6 @@ class PluginManager(object):
|
|||
def checkCommandExist(self,pluginName,commandId):
|
||||
# Not implemented yet
|
||||
pass
|
||||
|
||||
def printQueueSize(self):
|
||||
print("size " + str(len(self.pluginQueueDict)))
|
||||
|
|
Loading…
Reference in a new issue