fix: gitignore + testing map structure
ref: N25B-205
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -199,7 +199,7 @@ cython_debug/
|
|||||||
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
||||||
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
||||||
# you could uncomment the following to ignore the entire vscode folder
|
# you could uncomment the following to ignore the entire vscode folder
|
||||||
# .vscode/
|
.vscode/
|
||||||
|
|
||||||
# Ruff stuff:
|
# Ruff stuff:
|
||||||
.ruff_cache/
|
.ruff_cache/
|
||||||
|
|||||||
26
src/control_backend/api/v1/endpoints/sse_ping.py
Normal file
26
src/control_backend/api/v1/endpoints/sse_ping.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
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
|
from control_backend.api.v1.endpoints import message, sse, sse_ping
|
||||||
|
|
||||||
api_router = APIRouter()
|
api_router = APIRouter()
|
||||||
|
|
||||||
@@ -13,3 +13,8 @@ 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