mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-20 07:14:20 +01:00
Improve log messages on reconnection in BfxWebsocketClient (bfxapi.websocket.client.bfx_websocket_client).
This commit is contained in:
@@ -121,11 +121,11 @@ class BfxWebsocketClient:
|
|||||||
async def _connection():
|
async def _connection():
|
||||||
nonlocal reconnection, timer, tasks
|
nonlocal reconnection, timer, tasks
|
||||||
|
|
||||||
async with websockets.connect(self.host) as websocket:
|
async with websockets.connect(self.host, ping_interval=None) as websocket:
|
||||||
if reconnection.status:
|
if reconnection.status:
|
||||||
self.logger.info(f"Reconnect attempt successful (attempt no.{reconnection.attempts}): The " \
|
self.logger.info(f"Reconnection attempt successful (no.{reconnection.attempts}): The " \
|
||||||
f"client has been offline for a total of {datetime.now() - reconnection.timestamp} " \
|
f"client has been offline for a total of {datetime.now() - reconnection.timestamp} " \
|
||||||
f"(connection lost at: {reconnection.timestamp:%d-%m-%Y at %H:%M:%S}).")
|
f"(connection lost on: {reconnection.timestamp:%d-%m-%Y at %H:%M:%S}).")
|
||||||
|
|
||||||
reconnection = Reconnection(status=False, attempts=0, timestamp=None)
|
reconnection = Reconnection(status=False, attempts=0, timestamp=None)
|
||||||
|
|
||||||
@@ -188,11 +188,11 @@ class BfxWebsocketClient:
|
|||||||
if error.code in (1006, 1012):
|
if error.code in (1006, 1012):
|
||||||
if error.code == 1006:
|
if error.code == 1006:
|
||||||
self.logger.error("Connection lost: no close frame received " \
|
self.logger.error("Connection lost: no close frame received " \
|
||||||
"or sent (1006). Attempting to reconnect...")
|
"or sent (1006). Trying to reconnect...")
|
||||||
|
|
||||||
if error.code == 1012:
|
if error.code == 1012:
|
||||||
self.logger.info("WSS server is about to restart, reconnection " \
|
self.logger.info("WSS server is about to restart, clients need " \
|
||||||
"required (client received 20051). Attempt in progress...")
|
"to reconnect (server sent 20051). Reconnection attempt in progress...")
|
||||||
|
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
@@ -203,8 +203,8 @@ class BfxWebsocketClient:
|
|||||||
|
|
||||||
self.authentication = False
|
self.authentication = False
|
||||||
elif isinstance(error, socket.gaierror) and reconnection.status:
|
elif isinstance(error, socket.gaierror) and reconnection.status:
|
||||||
self.logger.warning(f"Reconnection attempt no.{reconnection.attempts} has failed. " \
|
self.logger.warning(f"Reconnection attempt was unsuccessful (no.{reconnection.attempts}). " \
|
||||||
f"Next reconnection attempt in ~{round(delay.peek()):.1f} seconds. (at the moment " \
|
f"Next reconnection attempt in {delay.peek():.2f} seconds. (at the moment " \
|
||||||
f"the client has been offline for {datetime.now() - reconnection.timestamp})")
|
f"the client has been offline for {datetime.now() - reconnection.timestamp})")
|
||||||
|
|
||||||
reconnection = reconnection._replace(attempts=reconnection.attempts + 1)
|
reconnection = reconnection._replace(attempts=reconnection.attempts + 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user