Cleanup websocket on error
This commit is contained in:
parent
81d879c9ee
commit
fcc136ae18
1 changed files with 6 additions and 1 deletions
|
@ -24,6 +24,8 @@ class PushbulletBackend(Backend):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _on_error(ws, e):
|
def _on_error(ws, e):
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
|
self.ws.close()
|
||||||
|
self._init_socket()
|
||||||
|
|
||||||
def _on_push(self, data):
|
def _on_push(self, data):
|
||||||
data = json.loads(data) if isinstance(data, str) else push
|
data = json.loads(data) if isinstance(data, str) else push
|
||||||
|
@ -45,7 +47,7 @@ class PushbulletBackend(Backend):
|
||||||
|
|
||||||
self.on_msg(body)
|
self.on_msg(body)
|
||||||
|
|
||||||
def run(self):
|
def _init_socket(self):
|
||||||
self.ws = websocket.WebSocketApp(
|
self.ws = websocket.WebSocketApp(
|
||||||
'wss://stream.pushbullet.com/websocket/' + self.token,
|
'wss://stream.pushbullet.com/websocket/' + self.token,
|
||||||
on_open = self._on_init,
|
on_open = self._on_init,
|
||||||
|
@ -54,6 +56,9 @@ class PushbulletBackend(Backend):
|
||||||
on_close = self._on_close)
|
on_close = self._on_close)
|
||||||
|
|
||||||
self.ws.backend = self
|
self.ws.backend = self
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.init_socket()
|
||||||
self.ws.run_forever()
|
self.ws.run_forever()
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue