Files
appfactory-portal/app/routes/operations.py
T
2026-06-17 11:39:52 +02:00

27 lines
799 B
Python

import asyncio
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
from app.auth import current_user
from app.db.operations import get_operations_snapshot
router = APIRouter()
# Stránka "Přehled" (/portal/operations) byla odstraněna. Tento WebSocket ale dál pohání živé
# počty a tabulky na stránkách Úlohy, Workery a Incidenty (operations-live.js), proto zůstává.
@router.websocket("/ws/operations")
async def operations_websocket(websocket: WebSocket):
user = current_user(websocket)
if not user:
await websocket.close(code=1008)
return
await websocket.accept()
try:
while True:
await websocket.send_json(get_operations_snapshot())
await asyncio.sleep(2)
except WebSocketDisconnect:
return