mirror of
https://github.com/Pardus-LiderAhenk/ahenk
synced 2024-12-23 13:22:17 +03:00
xmpp reconnection
This commit is contained in:
parent
36244b3723
commit
014dd0f468
2 changed files with 7 additions and 18 deletions
|
@ -98,8 +98,8 @@ class AhenkDeamon(BaseDaemon):
|
|||
|
||||
def init_messager(self):
|
||||
messenger = Messager()
|
||||
messanger_thread = threading.Thread(target=messenger.connect_to_server)
|
||||
messanger_thread.start()
|
||||
messenger_thread = threading.Thread(target=messenger.connect_to_server)
|
||||
messenger_thread.start()
|
||||
|
||||
while messenger.is_connected() is False:
|
||||
time.sleep(1)
|
||||
|
@ -219,12 +219,13 @@ class AhenkDeamon(BaseDaemon):
|
|||
signal.signal(signal.SIGALRM, self.signal_handler)
|
||||
logger.info('[AhenkDeamon] Signal handler is set up')
|
||||
except Exception as e:
|
||||
logger.error('[AhenkDeamon] Signal handler could not set up :' + e.errno + '-' + e.strerror)
|
||||
logger.error('[AhenkDeamon] Signal handler could not set up. Error Message: {} '.format(str(e)))
|
||||
|
||||
messager.send_direct_message('test')
|
||||
|
||||
while True:
|
||||
if messager.ping_lider() is False:
|
||||
if messager.is_connected() is False:
|
||||
logger.debug('reconnecting')
|
||||
Scope.getInstance().getLogger().warning('[AhenkDeamon] Connection is lost. Ahenk is trying for reconnection')
|
||||
messager = self.init_messager()
|
||||
time.sleep(1)
|
||||
|
|
|
@ -41,18 +41,6 @@ class Messager(slixmpp.ClientXMPP):
|
|||
self.register_extensions()
|
||||
self.add_listeners()
|
||||
|
||||
def ping_lider(self):
|
||||
try:
|
||||
result = self['xep_0199'].send_ping(jid=self.receiver,timeout=10)
|
||||
if result is False:
|
||||
self.logger.debug('[Messager] Couldn\'t send ping to lider.')
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error('[Messager] A problem occurred while pinging to lider. Error Message:{}'.format(str(e)))
|
||||
return False
|
||||
|
||||
def add_listeners(self):
|
||||
self.add_event_handler('session_start', self.session_start)
|
||||
self.add_event_handler('session_end', self.session_end)
|
||||
|
@ -133,7 +121,7 @@ class Messager(slixmpp.ClientXMPP):
|
|||
j = json.loads(str(msg['body']))
|
||||
self.logger.debug('[Messager] Received message: {}'.format(str(msg['body'])))
|
||||
message_type = j['type']
|
||||
self.logger.debug('[Messager] Fired event is: {}' .format(message_type))
|
||||
self.logger.debug('[Messager] Fired event is: {}'.format(message_type))
|
||||
print('----->' + str(msg['body']))
|
||||
self.event_manger.fireEvent(message_type, str(msg['body']))
|
||||
|
||||
|
@ -147,7 +135,7 @@ class Messager(slixmpp.ClientXMPP):
|
|||
self.logger.debug('[Messager] Connection were established successfully')
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error('[Messager] Connection to server is failed! ' + e)
|
||||
self.logger.error('[Messager] Connection to server is failed! Error Message: {}'.format(str(e)))
|
||||
return False
|
||||
|
||||
def set_file_name_md5(self):
|
||||
|
|
Loading…
Reference in a new issue