Set function cancel_all_tasks for events got_offline and presence_unavailable.

This commit is contained in:
Schimon Jehudah, Adv. 2024-11-27 13:05:05 +02:00
parent 7e2724b663
commit 442fa016f0

View file

@ -260,7 +260,7 @@ class XmppClient(slixmpp.ClientXMPP):
self.add_event_handler("session_resumed", self.add_event_handler("session_resumed",
self.on_session_resumed) self.on_session_resumed)
self.add_event_handler("got_offline", self.add_event_handler("got_offline",
self.on_got_offline) self.cancel_all_tasks)
self.add_event_handler("changed_status", self.add_event_handler("changed_status",
self.on_changed_status) self.on_changed_status)
self.add_event_handler("disco_info", self.add_event_handler("disco_info",
@ -268,7 +268,7 @@ class XmppClient(slixmpp.ClientXMPP):
self.add_event_handler("presence_available", self.add_event_handler("presence_available",
self.on_presence_available) self.on_presence_available)
self.add_event_handler("presence_unavailable", self.add_event_handler("presence_unavailable",
self.on_presence_unavailable) self.cancel_all_tasks)
self.add_event_handler("chatstate_active", self.add_event_handler("chatstate_active",
self.on_chatstate_active) self.on_chatstate_active)
self.add_event_handler("chatstate_composing", self.add_event_handler("chatstate_composing",
@ -530,11 +530,6 @@ class XmppClient(slixmpp.ClientXMPP):
difference)) difference))
async def on_got_offline(self, presence):
breakpoint()
# await task.check_readiness(self, presence)
async def on_changed_status(self, presence): async def on_changed_status(self, presence):
time_begin = time.time() time_begin = time.time()
jid_full = presence['from'].full jid_full = presence['from'].full
@ -657,15 +652,17 @@ class XmppClient(slixmpp.ClientXMPP):
difference)) difference))
def on_presence_unavailable(self, presence): def cancel_all_tasks(self, presence):
time_begin = time.time() time_begin = time.time()
jid_full = presence['from'].full jid_full = presence['from'].full
function_name = sys._getframe().f_code.co_name function_name = sys._getframe().f_code.co_name
message_log = '{}: jid_full: {}' message_log = '{}: jid_full: {}'
logger.debug(message_log.format(function_name, jid_full)) logger.debug(message_log.format(function_name, jid_full))
jid_bare = presence['from'].bare jid_bare = presence['from'].bare
for task in ('check', 'interval', 'status'): for task in ('check', 'interval', 'status'):
Task.stop(self, jid_bare, 'status') Task.stop(self, jid_bare, 'status')
time_end = time.time() time_end = time.time()
difference = time_end - time_begin difference = time_end - time_begin
if difference > 1: logger.warning('{} (time: {})'.format(function_name, if difference > 1: logger.warning('{} (time: {})'.format(function_name,