Websocket changes

This commit is contained in:
2026-02-22 22:01:11 +01:00 Verified
parent 1377a97398
commit a2d76f2b7a
2 changed files with 9 additions and 2 deletions
+1 -1
View File
@@ -14,4 +14,4 @@ COPY ./app ./app
RUN mkdir -p /app/data
EXPOSE $PORT
CMD ["sh", "-c", "gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:$PORT"]
CMD ["sh", "-c", "gunicorn -w 1 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:$PORT"]
+8 -1
View File
@@ -1,4 +1,6 @@
# backend/app/routes/websocket.py
import asyncio
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from ..core.websocket_manager import manager
@@ -11,6 +13,11 @@ async def websocket_endpoint(websocket: WebSocket):
await manager.connect(websocket)
try:
while True:
await websocket.receive_text()
try:
await asyncio.wait_for(websocket.receive_text(), timeout=30.0)
except asyncio.TimeoutError:
await websocket.send_json({"type": "ping"})
except WebSocketDisconnect:
manager.disconnect(websocket)
except Exception:
manager.disconnect(websocket)