Websocket changes
This commit is contained in:
+1
-1
@@ -14,4 +14,4 @@ COPY ./app ./app
|
|||||||
RUN mkdir -p /app/data
|
RUN mkdir -p /app/data
|
||||||
EXPOSE $PORT
|
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
|
# backend/app/routes/websocket.py
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
||||||
|
|
||||||
from ..core.websocket_manager import manager
|
from ..core.websocket_manager import manager
|
||||||
@@ -11,6 +13,11 @@ async def websocket_endpoint(websocket: WebSocket):
|
|||||||
await manager.connect(websocket)
|
await manager.connect(websocket)
|
||||||
try:
|
try:
|
||||||
while True:
|
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:
|
except WebSocketDisconnect:
|
||||||
manager.disconnect(websocket)
|
manager.disconnect(websocket)
|
||||||
|
except Exception:
|
||||||
|
manager.disconnect(websocket)
|
||||||
|
|||||||
Reference in New Issue
Block a user