Merge pull request #12 from lnbits/test/tear_down_ws

Test/tear down ws
This commit is contained in:
calle 2023-04-18 18:56:12 +02:00 committed by GitHub
commit 9cd757e81d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,7 +35,7 @@ class Relay:
self.reconnect: bool = True
self.shutdown: bool = False
self.error_counter: int = 0
self.error_threshold: int = 0
self.error_threshold: int = 100
self.num_received_events: int = 0
self.num_sent_events: int = 0
self.num_subscriptions: int = 0
@ -43,8 +43,10 @@ class Relay:
self.proxy: dict = {}
self.lock = Lock()
self.queue = Queue()
def connect(self, ssl_options: dict = None, proxy: dict = None):
self.ws = WebSocketApp(
url,
self.url,
on_open=self._on_open,
on_message=self._on_message,
on_error=self._on_error,
@ -52,8 +54,6 @@ class Relay:
on_ping=self._on_ping,
on_pong=self._on_pong,
)
def connect(self, ssl_options: dict = None, proxy: dict = None):
self.ssl_options = ssl_options
self.proxy = proxy
if not self.connected:
@ -76,7 +76,7 @@ class Relay:
pass
self.connected = False
if self.reconnect:
time.sleep(1)
time.sleep(self.error_counter**2)
self.connect(self.ssl_options, self.proxy)
@property
@ -129,6 +129,10 @@ class Relay:
def _on_close(self, class_obj, status_code, message):
self.connected = False
if self.error_threshold and self.error_counter > self.error_threshold:
pass
else:
self.check_reconnect()
pass
def _on_message(self, class_obj, message: str):
@ -139,10 +143,6 @@ class Relay:
def _on_error(self, class_obj, error):
self.connected = False
self.error_counter += 1
if self.error_threshold and self.error_counter > self.error_threshold:
pass
else:
self.check_reconnect()
def _on_ping(self, class_obj, message):
return