feat: queue de téléchargement séquentielle (un à la fois)
Docker / docker (push) Successful in 1m38s
Docker / docker (push) Successful in 1m38s
asyncio.Queue dans DownloadManager + worker unique démarré dans le lifespan. Les téléchargements s'exécutent un par un dans l'ordre d'arrivée. Suppression de BackgroundTasks (plus nécessaire). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ import os
|
||||
import re
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import BackgroundTasks, FastAPI, HTTPException, Request
|
||||
from fastapi import FastAPI, HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse, StreamingResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.templating import Jinja2Templates
|
||||
@@ -52,13 +52,14 @@ async def _auto_dl_loop():
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
task = asyncio.create_task(_auto_dl_loop())
|
||||
tasks = [
|
||||
asyncio.create_task(dm.start_worker()),
|
||||
asyncio.create_task(_auto_dl_loop()),
|
||||
]
|
||||
yield
|
||||
task.cancel()
|
||||
try:
|
||||
await task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
for t in tasks:
|
||||
t.cancel()
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
|
||||
|
||||
app = FastAPI(title="Arte-dl", lifespan=lifespan)
|
||||
@@ -133,10 +134,10 @@ class DownloadRequest(BaseModel):
|
||||
|
||||
|
||||
@app.post("/api/download")
|
||||
async def api_download(req: DownloadRequest, bg: BackgroundTasks):
|
||||
async def api_download(req: DownloadRequest):
|
||||
if not req.url:
|
||||
raise HTTPException(status_code=400, detail="url required")
|
||||
dl_id = dm.enqueue(req.url, req.title, req.subtitle, req.year, req.category, bg)
|
||||
dl_id = await dm.enqueue(req.url, req.title, req.subtitle, req.year, req.category)
|
||||
return {"id": dl_id}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user