Karan Adhikari commited on
Introduce INACTIVE_TIMEOUT for stream status management
Browse filesAdded INACTIVE_TIMEOUT constant to manage stream inactivity.
Backend/fastapi/routes/stream_routes.py
CHANGED
|
@@ -386,11 +386,15 @@ async def media_streamer(
|
|
| 386 |
async def get_stream_stats():
|
| 387 |
now = time.time()
|
| 388 |
PRUNE_SECONDS = 3
|
|
|
|
| 389 |
|
| 390 |
for sid, info in list(ACTIVE_STREAMS.items()):
|
| 391 |
status = info.get("status")
|
| 392 |
# Check end_ts first, which is set when a stream organically finishes
|
| 393 |
last_ts = info.get("end_ts") or info.get("last_ts") or info.get("start_ts", now)
|
|
|
|
|
|
|
|
|
|
| 394 |
if status in ("cancelled", "error", "finished"):
|
| 395 |
if now - last_ts > PRUNE_SECONDS:
|
| 396 |
try:
|
|
@@ -455,4 +459,4 @@ async def get_stream_detail(stream_id: str):
|
|
| 455 |
if rec.get("stream_id") == stream_id:
|
| 456 |
return JSONResponse(make_json_safe(rec))
|
| 457 |
|
| 458 |
-
raise HTTPException(status_code=404, detail="Stream not found")
|
|
|
|
| 386 |
async def get_stream_stats():
|
| 387 |
now = time.time()
|
| 388 |
PRUNE_SECONDS = 3
|
| 389 |
+
INACTIVE_TIMEOUT = 10
|
| 390 |
|
| 391 |
for sid, info in list(ACTIVE_STREAMS.items()):
|
| 392 |
status = info.get("status")
|
| 393 |
# Check end_ts first, which is set when a stream organically finishes
|
| 394 |
last_ts = info.get("end_ts") or info.get("last_ts") or info.get("start_ts", now)
|
| 395 |
+
if status == "active" and (now - last_ts > INACTIVE_TIMEOUT):
|
| 396 |
+
info["status"] = "finished"
|
| 397 |
+
info["end_ts"] = last_ts
|
| 398 |
if status in ("cancelled", "error", "finished"):
|
| 399 |
if now - last_ts > PRUNE_SECONDS:
|
| 400 |
try:
|
|
|
|
| 459 |
if rec.get("stream_id") == stream_id:
|
| 460 |
return JSONResponse(make_json_safe(rec))
|
| 461 |
|
| 462 |
+
raise HTTPException(status_code=404, detail="Stream not found")
|