More robust websocket retry handler for Todoist

This commit is contained in:
Fabio Manganiello 2020-09-04 22:59:23 +02:00
parent d27b23ec5a
commit 2ceb3511b3

View file

@ -58,22 +58,27 @@ class TodoistBackend(Backend):
return hndl 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): def _on_error(self):
# noinspection PyUnusedLocal # noinspection PyUnusedLocal
def hndl(ws, error): def hndl(ws, error):
self.logger.warning('Todoist websocket error: {}'.format(error)) self.logger.warning('Todoist websocket error: {}'.format(error))
self._retry_hndl()
return hndl return hndl
def _on_close(self): def _on_close(self):
# noinspection PyUnusedLocal def hndl(*_, **__):
def hndl(ws): self.logger.info('Todoist websocket closed')
self._ws = None self._retry_hndl()
self.logger.warning('Todoist websocket connection closed')
self._connected = False
while not self._connected:
self._connect()
time.sleep(10)
return hndl return hndl