Skip to content

Create SSE streaming endpoint for real-time health updates #71

@lbedner

Description

@lbedner

Objective

Implement a Server-Sent Events (SSE) endpoint that streams real-time health and queue updates to the dashboard.

Tasks

  • Add sse-starlette dependency to requirements
  • Create /health/stream endpoint for SSE streaming
  • Implement async generator for streaming responses
  • Add connection management for multiple concurrent clients
  • Handle client disconnections gracefully
  • Implement heartbeat/keepalive messages

Technical Requirements

  • Use FastAPI's StreamingResponse or sse-starlette's EventSourceResponse
  • Support multiple concurrent SSE connections
  • Implement proper error handling and connection cleanup
  • Add rate limiting to prevent abuse
  • Include authentication/authorization checks

Example Implementation

from sse_starlette.sse import EventSourceResponse

@router.get('/health/stream')
async def health_stream(request: Request):
    async def event_generator():
        while True:
            if await request.is_disconnected():
                break
            data = await get_health_update()
            yield {"data": json.dumps(data)}
            await asyncio.sleep(1)
    
    return EventSourceResponse(event_generator())

Dependencies

  • Requires ASGI server (Uvicorn) for proper async support
  • May need to adjust CORS settings for SSE

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions