Add live request pipeline recheck
This commit is contained in:
@@ -1599,6 +1599,69 @@ async def get_snapshot(request_id: str, user: Dict[str, str] = Depends(get_curre
|
||||
return _filter_snapshot_actions_for_user(snapshot, user)
|
||||
|
||||
|
||||
@router.post("/{request_id}/actions/recheck")
|
||||
async def action_recheck(request_id: str, user: Dict[str, str] = Depends(get_current_user)) -> dict:
|
||||
if not request_id.isdigit():
|
||||
raise HTTPException(status_code=400, detail="Invalid request id")
|
||||
|
||||
runtime = get_runtime_settings()
|
||||
seerr = JellyseerrClient(runtime.jellyseerr_base_url, runtime.jellyseerr_api_key)
|
||||
if not seerr.configured():
|
||||
raise HTTPException(status_code=400, detail="Seerr is not configured")
|
||||
await _ensure_request_access(seerr, int(request_id), user)
|
||||
|
||||
try:
|
||||
fresh_request = await seerr.get_request(request_id)
|
||||
except httpx.HTTPStatusError as exc:
|
||||
detail = _format_upstream_error("Seerr", exc)
|
||||
await asyncio.to_thread(
|
||||
save_action,
|
||||
request_id,
|
||||
"recheck_pipeline",
|
||||
"Recheck request status",
|
||||
"failed",
|
||||
detail,
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
except Exception as exc:
|
||||
logger.warning("Request recheck failed while reading Seerr: request_id=%s error=%s", request_id, exc)
|
||||
detail = "Magent could not reach Seerr to recheck this request."
|
||||
await asyncio.to_thread(
|
||||
save_action,
|
||||
request_id,
|
||||
"recheck_pipeline",
|
||||
"Recheck request status",
|
||||
"failed",
|
||||
detail,
|
||||
)
|
||||
raise HTTPException(status_code=502, detail=detail) from exc
|
||||
|
||||
if not isinstance(fresh_request, dict):
|
||||
raise HTTPException(status_code=404, detail="Request not found in Seerr")
|
||||
|
||||
parsed = _parse_request_payload(fresh_request)
|
||||
if parsed.get("request_id") != int(request_id):
|
||||
raise HTTPException(status_code=502, detail="Seerr returned an unexpected request record")
|
||||
|
||||
cache_record = _build_request_cache_record(parsed, fresh_request)
|
||||
await asyncio.to_thread(upsert_request_cache, **cache_record)
|
||||
_cache_set(f"request:{request_id}", fresh_request)
|
||||
_refresh_recent_cache_from_db()
|
||||
|
||||
snapshot = _filter_snapshot_actions_for_user(await build_snapshot(request_id), user)
|
||||
status_label = str((snapshot.presentation.get("status") or {}).get("label") or "Status updated")
|
||||
message = f"Recheck complete. {status_label}."
|
||||
await asyncio.to_thread(
|
||||
save_action,
|
||||
request_id,
|
||||
"recheck_pipeline",
|
||||
"Recheck request status",
|
||||
"ok",
|
||||
message,
|
||||
)
|
||||
return {"status": "ok", "message": message, "snapshot": snapshot}
|
||||
|
||||
|
||||
@router.get("/{request_id}/download-progress")
|
||||
async def get_download_progress(
|
||||
request_id: str, user: Dict[str, str] = Depends(get_current_user)
|
||||
|
||||
Reference in New Issue
Block a user