Background long-running actions; confirm destructive ones
- Run now (jobs and playlists), dedup scan, genre preview/apply, and manual import now dispatch via BackgroundTasks and redirect immediately, instead of awaiting a job that can run for the better part of an hour and hang the browser or reverse proxy. Progress shows in the Jobs runs table (which already polls); if the pipeline is busy the run records skipped_lock there. - Fix the import banner, which claimed work was ongoing after the request had actually blocked to completion; it now reflects the backgrounded start. - Add confirmation prompts to the dedup per-row and bulk delete and to "Fix genres now", matching the existing confirms on library and playlist deletes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+10
-7
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request
|
||||
from fastapi.responses import PlainTextResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
from sqlalchemy import select
|
||||
@@ -67,15 +67,18 @@ async def runs_table_partial(request: Request, user: dict = Depends(require_auth
|
||||
|
||||
|
||||
@router.post("/{job_key:path}/run")
|
||||
async def run_now(job_key: str, user: dict = Depends(require_auth)):
|
||||
async def run_now(job_key: str, background: BackgroundTasks, user: dict = Depends(require_auth)):
|
||||
scheduler = scheduler_service.get_scheduler()
|
||||
if scheduler is None:
|
||||
raise HTTPException(503, "scheduler not running")
|
||||
try:
|
||||
await scheduler_service.trigger_now(scheduler, job_key)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(404, str(exc))
|
||||
return RedirectResponse(url="/settings/jobs", status_code=303)
|
||||
# Validate the job exists now (so a bad key still 404s), then run it in the
|
||||
# background and redirect immediately. A playlist sync can take the better
|
||||
# part of an hour; awaiting it here would hang the browser/reverse proxy.
|
||||
# Progress shows up in the runs table below, which polls every few seconds.
|
||||
if scheduler.get_job(job_key) is None:
|
||||
raise HTTPException(404, f"no such registered job: {job_key}")
|
||||
background.add_task(scheduler_service.trigger_now, scheduler, job_key)
|
||||
return RedirectResponse(url="/settings/jobs?started=1", status_code=303)
|
||||
|
||||
|
||||
@router.post("/{job_key:path}/toggle")
|
||||
|
||||
Reference in New Issue
Block a user