summaryrefslogtreecommitdiffhomepage
path: root/libs/signalrcore
diff options
context:
space:
mode:
authormorpheus65535 <[email protected]>2021-05-11 16:24:02 -0400
committermorpheus65535 <[email protected]>2021-05-11 16:24:02 -0400
commit84a1c265cea6ddc59c5dc4b43f756af7090e8cf8 (patch)
tree70f81210065ae3cd4fdb4fb939a1a8acc22cce3c /libs/signalrcore
parent63f759e91ed4f50da5f738cee81352ecc3c64326 (diff)
downloadbazarr-84a1c265cea6ddc59c5dc4b43f756af7090e8cf8.tar.gz
bazarr-84a1c265cea6ddc59c5dc4b43f756af7090e8cf8.zip
Improved Radarr SignalR feed reconnection process.
Diffstat (limited to 'libs/signalrcore')
-rw-r--r--libs/signalrcore/hub/base_hub_connection.py10
-rw-r--r--libs/signalrcore/transport/base_transport.py7
-rw-r--r--libs/signalrcore/transport/websockets/websocket_transport.py9
3 files changed, 24 insertions, 2 deletions
diff --git a/libs/signalrcore/hub/base_hub_connection.py b/libs/signalrcore/hub/base_hub_connection.py
index c9325bf63..f5c3dc342 100644
--- a/libs/signalrcore/hub/base_hub_connection.py
+++ b/libs/signalrcore/hub/base_hub_connection.py
@@ -77,6 +77,16 @@ class BaseHubConnection(object):
"""
self._on_error = callback
+ def on_reconnect(self, callback):
+ """Configures on_reconnect reconnection callback.
+ It will be raised on reconnection event
+ connection.on_reconnect(lambda: print(
+ "connection lost, reconnection in progress "))
+ Args:
+ callback (function): function without params
+ """
+ self.transport.on_reconnect_callback(callback)
+
def on(self, event, callback_function: Callable):
"""Register a callback on the specified event
Args:
diff --git a/libs/signalrcore/transport/base_transport.py b/libs/signalrcore/transport/base_transport.py
index c73a2c028..eeb3f7431 100644
--- a/libs/signalrcore/transport/base_transport.py
+++ b/libs/signalrcore/transport/base_transport.py
@@ -7,8 +7,8 @@ class BaseTransport(object):
self._on_message= on_message
self.logger = Helpers.get_logger()
self._on_open = lambda: self.logger.info("on_connect not defined")
- self._on_close = lambda: self.logger.info(
- "on_disconnect not defined")
+ self._on_close = lambda: self.logger.info("on_disconnect not defined")
+ self._on_reconnect = lambda: self.logger.info("on_reconnect not defined")
def on_open_callback(self, callback):
self._on_open = callback
@@ -16,6 +16,9 @@ class BaseTransport(object):
def on_close_callback(self, callback):
self._on_close = callback
+ def on_reconnect_callback(self, callback):
+ self._on_reconnect = callback
+
def start(self): # pragma: no cover
raise NotImplementedError()
diff --git a/libs/signalrcore/transport/websockets/websocket_transport.py b/libs/signalrcore/transport/websockets/websocket_transport.py
index 4c05add53..1b98c27e4 100644
--- a/libs/signalrcore/transport/websockets/websocket_transport.py
+++ b/libs/signalrcore/transport/websockets/websocket_transport.py
@@ -144,6 +144,12 @@ class WebsocketTransport(BaseTransport):
if self._on_close is not None and callable(self._on_close):
self._on_close()
+ def on_reconnect(self):
+ self.logger.debug("-- web socket reconnecting --")
+ self.state = ConnectionState.disconnected
+ if self._on_close is not None and callable(self._on_close):
+ self._on_close()
+
def on_socket_error(self, error):
"""
Throws error related on
@@ -217,6 +223,9 @@ class WebsocketTransport(BaseTransport):
raise ex
def handle_reconnect(self):
+ if not self.reconnection_handler.reconnecting and self._on_reconnect is not None and \
+ callable(self._on_reconnect):
+ self._on_reconnect()
self.reconnection_handler.reconnecting = True
try:
self.stop()