diff --git a/run.py b/run.py index 2f666a8..9bc32f6 100644 --- a/run.py +++ b/run.py @@ -512,8 +512,12 @@ async def ws_index(request, websocket): })) while True: - # do nothing with input but wait - await websocket.recv() + # ping periodically to remove dead connections + try: + await websocket.send("ping") + except ConnectionClosed: + return + await asyncio.sleep(60) @app.websocket('/job--ws') @@ -533,8 +537,12 @@ async def ws_job(request, websocket, job_id): })) while True: - # do nothing with input but wait - await websocket.recv() + # ping periodically to remove dead connections + try: + await websocket.send("ping") + except ConnectionClosed: + return + await asyncio.sleep(60) @app.websocket('/apps-ws') @@ -631,8 +639,12 @@ async def ws_apps(request, websocket): })) while True: - # do nothing with input but wait - await websocket.recv() + # ping periodically to remove dead connections + try: + await websocket.send("ping") + except ConnectionClosed: + return + await asyncio.sleep(60) @app.websocket('/app--ws') @@ -650,8 +662,12 @@ async def ws_app(request, websocket, app_name): })) while True: - # do nothing with input but wait - await websocket.recv() + # ping periodically to remove dead connections + try: + await websocket.send("ping") + except ConnectionClosed: + return + await asyncio.sleep(60) def require_token():