Set websocket open timeout to 1 minute and log connection attempts #3

Merged
hkc merged 3 commits from vftdan/mastoposter:log-websocket-connection into master 2024-06-12 23:32:35 +03:00
1 changed files with 8 additions and 2 deletions
Showing only changes of commit 3e82b5c979 - Show all commits

View File

@ -28,10 +28,16 @@ async def websocket_source(
from websockets.client import connect from websockets.client import connect
from websockets.exceptions import WebSocketException 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: while True:
try: 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:
Outdated
Review

maybe respect timeout option from main config here?

maybe respect timeout option from main config here?
logger.info("Connected to WebSocket")
while (msg := await ws.recv()) is not None: while (msg := await ws.recv()) is not None:
event = loads(msg) event = loads(msg)
logger.debug("data: %r", event) logger.debug("data: %r", event)