fix: router changes + hopefully gitignore
ref: N25B-205
This commit is contained in:
@@ -1,26 +0,0 @@
|
|||||||
from fastapi import APIRouter, Request
|
|
||||||
from fastapi.responses import StreamingResponse
|
|
||||||
import datetime
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
@router.get("/sse_ping")
|
|
||||||
async def sse_ping(request: Request):
|
|
||||||
"""
|
|
||||||
Endpoint for Server-Sent Events.
|
|
||||||
"""
|
|
||||||
async def event_generator():
|
|
||||||
while True:
|
|
||||||
# If connection to client closes, stop sending events
|
|
||||||
if await request.is_disconnected():
|
|
||||||
break
|
|
||||||
|
|
||||||
# Send message containing current time every second
|
|
||||||
current_time = datetime.datetime.now().strftime("%H:%M:%S")
|
|
||||||
yield f"data: Server time: {current_time}\n\n" # \n\n is needed to separate events (SSE is text-based)
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
return StreamingResponse(event_generator(), media_type="text/event-stream") # media_type specifies that this connection is for event streams
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from fastapi.routing import APIRouter
|
from fastapi.routing import APIRouter
|
||||||
|
|
||||||
from control_backend.api.v1.endpoints import message, sse, sse_ping
|
from control_backend.api.v1.endpoints import message, sse
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
|
|
||||||
@@ -12,9 +12,4 @@ api_router.include_router(
|
|||||||
api_router.include_router(
|
api_router.include_router(
|
||||||
sse.router,
|
sse.router,
|
||||||
tags=["SSE"]
|
tags=["SSE"]
|
||||||
)
|
)
|
||||||
|
|
||||||
api_router.include_router(
|
|
||||||
sse_ping.router,
|
|
||||||
tags=["SSE_ping"]
|
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user