mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 14:27:42 +00:00
Code review fixes
This commit is contained in:
@@ -50,8 +50,13 @@ class WebsocketSpotProvider(SpotProvider):
|
||||
self.status = "Connecting"
|
||||
self._ws = create_connection(self._url, header=HTTP_HEADERS)
|
||||
self.status = "Connected"
|
||||
data = self._ws.recv()
|
||||
if data:
|
||||
|
||||
# Keep reading from this same connection until it drops or we're asked to stop, rather than
|
||||
# reconnecting for every message.
|
||||
while not self._stopped:
|
||||
data = self._ws.recv()
|
||||
if not data:
|
||||
break
|
||||
try:
|
||||
new_spot = self._ws_message_to_spot(data)
|
||||
if new_spot:
|
||||
@@ -69,7 +74,16 @@ class WebsocketSpotProvider(SpotProvider):
|
||||
logger.exception(f"Exception in Websocket Spot Provider ({self.name})")
|
||||
else:
|
||||
self.status = "Disconnected"
|
||||
sleep(5) # Wait before trying to reconnect
|
||||
finally:
|
||||
if self._ws:
|
||||
try:
|
||||
self._ws.close()
|
||||
except Exception:
|
||||
# No problem, we were getting rid of this object anyway.
|
||||
pass
|
||||
self._ws = None
|
||||
if not self._stopped:
|
||||
sleep(5) # Wait before trying to reconnect
|
||||
|
||||
def _ws_message_to_spot(self, b):
|
||||
"""Convert a WS message received from the API into a spot. The exact message data (in bytes) is provided here so the
|
||||
|
||||
Reference in New Issue
Block a user