From 2ceb3511b354eaf7beb5965d1ba448cbf54a3244 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 4 Sep 2020 22:59:23 +0200 Subject: [PATCH] More robust websocket retry handler for Todoist --- platypush/backend/todoist.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/platypush/backend/todoist.py b/platypush/backend/todoist.py index b493ab2691..b4cb86885e 100644 --- a/platypush/backend/todoist.py +++ b/platypush/backend/todoist.py @@ -58,22 +58,27 @@ class TodoistBackend(Backend): return hndl + def _retry_hndl(self): + self._ws = None + self.logger.warning('Todoist websocket connection closed') + self._connected = False + + while not self._connected: + self._connect() + time.sleep(10) + def _on_error(self): # noinspection PyUnusedLocal def hndl(ws, error): self.logger.warning('Todoist websocket error: {}'.format(error)) + self._retry_hndl() + return hndl def _on_close(self): - # noinspection PyUnusedLocal - def hndl(ws): - self._ws = None - self.logger.warning('Todoist websocket connection closed') - self._connected = False - - while not self._connected: - self._connect() - time.sleep(10) + def hndl(*_, **__): + self.logger.info('Todoist websocket closed') + self._retry_hndl() return hndl