download the queue

This commit is contained in:
2025-11-01 16:13:28 +01:00
parent eaf6bb9957
commit 33aeac0141
4 changed files with 176 additions and 108 deletions

View File

@@ -280,25 +280,29 @@ async def start_queue(
_: dict = Depends(require_auth),
download_service: DownloadService = Depends(get_download_service),
):
"""Start the next download from pending queue.
"""Start automatic queue processing.
Manually starts the first pending download in the queue. Only one download
can be active at a time. If the queue is empty or a download is already
active, an error is returned.
Starts processing all pending downloads sequentially, one at a time.
The queue will continue processing until all items are complete or
the queue is manually stopped. Processing continues even if the browser
is closed.
Only one download can be active at a time. If a download is already
active or queue processing is running, an error is returned.
Requires authentication.
Returns:
dict: Status message with started item ID
dict: Status message confirming queue processing started
Raises:
HTTPException: 401 if not authenticated, 400 if queue is empty or
download already active, 500 on service error
processing already active, 500 on service error
"""
try:
item_id = await download_service.start_next_download()
result = await download_service.start_queue_processing()
if item_id is None:
if result is None:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="No pending downloads in queue",
@@ -306,8 +310,7 @@ async def start_queue(
return {
"status": "success",
"message": "Download started",
"item_id": item_id,
"message": "Queue processing started",
}
except DownloadServiceError as e:
@@ -320,7 +323,7 @@ async def start_queue(
except Exception as e:
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail=f"Failed to start download: {str(e)}",
detail=f"Failed to start queue processing: {str(e)}",
)