From 4410009015e509ad7cc145db2aa130d3bba271c2 Mon Sep 17 00:00:00 2001 From: Vftdan Date: Fri, 3 May 2024 19:07:12 +0200 Subject: [PATCH] Set websocket open timeout to 1 minute and log attempts --- mastoposter/sources.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mastoposter/sources.py b/mastoposter/sources.py index 749ad4d..8207aed 100644 --- a/mastoposter/sources.py +++ b/mastoposter/sources.py @@ -28,10 +28,16 @@ async def websocket_source( from websockets.client import connect from websockets.exceptions import WebSocketException - url = f"{url}?" + urlencode({"stream": "list", **params}) + param_dict = {"stream": "list", **params} + public_param_dict = param_dict.copy() + public_param_dict["access_token"] = 'SCRUBBED' + public_url = f"{url}?" + urlencode(public_param_dict) + url = f"{url}?" + urlencode(param_dict) while True: try: - async with connect(url) as ws: + logger.info("attempting to connect to %s", public_url) + async with connect(url, open_timeout=60) as ws: + logger.info("Connected to WebSocket") while (msg := await ws.recv()) is not None: event = loads(msg) logger.debug("data: %r", event)