queue fix
This commit is contained in:
@@ -43,39 +43,27 @@ async def get_queue_status(
|
||||
queue_status = await download_service.get_queue_status()
|
||||
queue_stats = await download_service.get_queue_stats()
|
||||
|
||||
# Preserve the legacy response contract expected by the original CLI
|
||||
# client and existing integration tests. Those consumers still parse
|
||||
# the bare dictionaries that the pre-FastAPI implementation emitted,
|
||||
# so we keep the canonical field names (``active``/``pending``/
|
||||
# ``completed``/``failed``) and dump each Pydantic object to plain
|
||||
# JSON-compatible dicts instead of returning the richer
|
||||
# ``QueueStatusResponse`` shape directly. This guarantees both the
|
||||
# CLI and older dashboard widgets do not need schema migrations while
|
||||
# the new web UI can continue to evolve independently.
|
||||
status_payload = {
|
||||
"is_running": queue_status.is_running,
|
||||
"is_paused": queue_status.is_paused,
|
||||
"active": [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.active_downloads
|
||||
],
|
||||
"pending": [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.pending_queue
|
||||
],
|
||||
"completed": [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.completed_downloads
|
||||
],
|
||||
"failed": [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.failed_downloads
|
||||
],
|
||||
}
|
||||
# Build response with field names expected by frontend
|
||||
# Frontend expects top-level arrays (active_downloads, pending_queue, etc.)
|
||||
# not nested under a 'status' object
|
||||
active_downloads = [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.active_downloads
|
||||
]
|
||||
pending_queue = [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.pending_queue
|
||||
]
|
||||
completed_downloads = [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.completed_downloads
|
||||
]
|
||||
failed_downloads = [
|
||||
it.model_dump(mode="json")
|
||||
for it in queue_status.failed_downloads
|
||||
]
|
||||
|
||||
# Add the derived ``success_rate`` metric so dashboards built against
|
||||
# the previous API continue to function without recalculating it
|
||||
# client-side.
|
||||
# Calculate success rate
|
||||
completed = queue_stats.completed_count
|
||||
failed = queue_stats.failed_count
|
||||
success_rate = None
|
||||
@@ -87,7 +75,12 @@ async def get_queue_status(
|
||||
|
||||
return JSONResponse(
|
||||
content={
|
||||
"status": status_payload,
|
||||
"is_running": queue_status.is_running,
|
||||
"is_paused": queue_status.is_paused,
|
||||
"active_downloads": active_downloads,
|
||||
"pending_queue": pending_queue,
|
||||
"completed_downloads": completed_downloads,
|
||||
"failed_downloads": failed_downloads,
|
||||
"statistics": stats_payload,
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user