From 1777ebb0516118cdef20046a92caab496fa7c6cb Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 30 Dec 2020 19:44:30 +0100 Subject: [PATCH] Retry logic in case of Pushbullet listener error --- platypush/backend/pushbullet/__init__.py | 25 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/platypush/backend/pushbullet/__init__.py b/platypush/backend/pushbullet/__init__.py index c3e905b25..e1fc67e01 100644 --- a/platypush/backend/pushbullet/__init__.py +++ b/platypush/backend/pushbullet/__init__.py @@ -124,14 +124,29 @@ class PushbulletBackend(Backend): def close(self): if self.listener: self.listener.close() + self.listener = None def on_stop(self): super().on_stop() return self.close() + def on_error(self, e): + self.logger.exception(e) + self.close() + self.run_listener() + + def run_listener(self): + from pushbullet import Listener + + self.logger.info('Initializing Pushbullet backend - device_id: {}'.format(self.device_name)) + self.listener = Listener(account=self.pb, on_push=self.on_push(), on_error=self.on_error, + http_proxy_host=self.proxy_host, + http_proxy_port=self.proxy_port) + + self.listener.run_forever() + def run(self): # noinspection PyPackageRequirements - from pushbullet import Listener super().run() initialized = False @@ -144,13 +159,7 @@ class PushbulletBackend(Backend): self.logger.error('Pushbullet initialization error: {}'.format(str(e))) time.sleep(30) - self.logger.info('Initialized Pushbullet backend - device_id: {}' - .format(self.device_name)) + self.run_listener() - self.listener = Listener(account=self.pb, on_push=self.on_push(), - http_proxy_host=self.proxy_host, - http_proxy_port=self.proxy_port) - - self.listener.run_forever() # vim:sw=4:ts=4:et: