From f8f67e76412c352895a9d254ad682dea328607f5 Mon Sep 17 00:00:00 2001 From: Thomas Howe Date: Sun, 8 Feb 2026 01:07:43 +0000 Subject: [PATCH] Add /stats/queue endpoint for Redis queue depth monitoring Public endpoint (no auth) that returns the depth of any Redis list, used by the audio adapter for backpressure control. Co-Authored-By: Claude Opus 4.6 --- server/api.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/api.py b/server/api.py index 3ec723d..d4532fe 100644 --- a/server/api.py +++ b/server/api.py @@ -260,6 +260,24 @@ async def health_check() -> JSONResponse: }) +@app.get( + "/stats/queue", + summary="Get queue depth", + description="Returns the number of items in a Redis list (queue)", + tags=["system"], +) +async def get_queue_depth( + list_name: str = Query(..., description="Name of the Redis list to measure") +) -> JSONResponse: + """Get the current depth of a Redis list. Public endpoint (no auth) for monitoring and backpressure.""" + try: + depth = await redis_async.llen(list_name) + return JSONResponse(content={"list_name": list_name, "depth": depth}) + except Exception as e: + logger.error(f"Error getting queue depth for '{list_name}': {str(e)}") + raise HTTPException(status_code=500, detail="Failed to get queue depth") + + class Vcon(BaseModel): """Pydantic model representing a vCon (Voice Conversation) record.