Websocket changes
This commit is contained in:
+1
-1
@@ -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"]
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user