mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-11-22 09:42:15 +03:00
event base docstring. response queue exception handling fix
This commit is contained in:
parent
cff628e5df
commit
f82e7c4f02
2 changed files with 27 additions and 10 deletions
|
@ -3,6 +3,11 @@
|
|||
# @author: İsmail BAŞARAN <ismail.basaran@tubitak.gov.tr> <basaran.ismaill@gmail.com>
|
||||
|
||||
class EventBase():
|
||||
|
||||
"""
|
||||
This is base event class for event management.
|
||||
"""
|
||||
|
||||
listeners = []
|
||||
|
||||
def __init__(self):
|
||||
|
@ -10,10 +15,22 @@ class EventBase():
|
|||
self.listener_events = []
|
||||
|
||||
def register_event(self, event_name, callback_func):
|
||||
"""
|
||||
Registers event listener.
|
||||
Args:
|
||||
event_name : name of event, user specify event name
|
||||
callback_func : when an event fire with specified event name this method will call
|
||||
"""
|
||||
self.listener_events.append({'event_name': event_name, 'callback_func': callback_func})
|
||||
|
||||
|
||||
class Event():
|
||||
"""
|
||||
This is event class. Takes two argument ;
|
||||
Args:
|
||||
event_name : name of event.
|
||||
callback_args : arguments specified by user. This function will transmit args to callback function directly.
|
||||
"""
|
||||
def __init__(self, event_name, *callback_args):
|
||||
for listener in EventBase.listeners:
|
||||
for listener_cls in listener.listener_events:
|
||||
|
|
|
@ -20,14 +20,14 @@ class MessageResponseQueue(threading.Thread):
|
|||
self.outQueue = outQueue
|
||||
|
||||
def run(self):
|
||||
try:
|
||||
while True:
|
||||
# This item will send response to lider.
|
||||
# item must be response message. Response message may be generic message type
|
||||
responseMessage = self.outQueue.get(block=True)
|
||||
print(responseMessage)
|
||||
# Call message manager for response
|
||||
self.messageManager.send_direct_message(responseMessage)
|
||||
# self.outQueue.task_done()
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
# This item will send response to lider.
|
||||
# item must be response message. Response message may be generic message type
|
||||
responseMessage = self.outQueue.get(block=True)
|
||||
self.logger.debug('[MessageResponseQueue] Sending response message to lider. Response Message ' + str(responseMessage))
|
||||
# Call message manager for response
|
||||
self.messageManager.send_direct_message(responseMessage)
|
||||
# self.outQueue.task_done()
|
||||
except Exception as e:
|
||||
self.logger.error
|
||||
|
|
Loading…
Reference in a new issue