Нормализовать переводы строк в LF
Решение по TD-STYLE-ANALYZERS: LF — инструменты проекта (Python/Node) пишут LF, CRLF-.sh не работают на Linux CI (sh scripts/ci.sh), большинство файлов уже были LF. Добавлен .gitattributes (* text=auto eol=lf, бинарные исключения), .editorconfig переведён на lf, 1029 файлов конвертированы, git add --renormalize. Из индекса убраны закравшиеся archive/**/__pycache__/*.pyc.
This commit is contained in:
@@ -1,38 +1,38 @@
|
||||
"""SSE-события (realtime) для фронтенда."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from ..auth import current_login
|
||||
from ..sse import broker
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["events"])
|
||||
|
||||
|
||||
@router.get("/events")
|
||||
async def events(request: Request, _: str = Depends(current_login)):
|
||||
async def stream():
|
||||
q = await broker.subscribe()
|
||||
try:
|
||||
while True:
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
try:
|
||||
yield await asyncio.wait_for(q.get(), timeout=15)
|
||||
except asyncio.TimeoutError:
|
||||
yield ": ping\n\n"
|
||||
finally:
|
||||
await broker.unsubscribe(q)
|
||||
|
||||
return StreamingResponse(
|
||||
stream(),
|
||||
media_type="text/event-stream",
|
||||
headers={
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
)
|
||||
"""SSE-события (realtime) для фронтенда."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import StreamingResponse
|
||||
|
||||
from ..auth import current_login
|
||||
from ..sse import broker
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["events"])
|
||||
|
||||
|
||||
@router.get("/events")
|
||||
async def events(request: Request, _: str = Depends(current_login)):
|
||||
async def stream():
|
||||
q = await broker.subscribe()
|
||||
try:
|
||||
while True:
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
try:
|
||||
yield await asyncio.wait_for(q.get(), timeout=15)
|
||||
except asyncio.TimeoutError:
|
||||
yield ": ping\n\n"
|
||||
finally:
|
||||
await broker.unsubscribe(q)
|
||||
|
||||
return StreamingResponse(
|
||||
stream(),
|
||||
media_type="text/event-stream",
|
||||
headers={
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive",
|
||||
"X-Accel-Buffering": "no",
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user