xmpp reconnection

This commit is contained in:
Volkan Şahin 2016-05-17 17:27:51 +03:00
parent 36244b3723
commit 014dd0f468
2 changed files with 7 additions and 18 deletions

View file

@ -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)

View file

@ -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)
@ -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):