Implements GET/DELETE /api/library, POST /api/library/{id}/reingest,
POST /api/library/scan, and GET /api/library/{id}/status. Adds FastAPI
app factory with lifespan migrations, BM25 singleton wiring, get_db
dependency, ingest task registry with cf-orch/BackgroundTasks fallback,
and placeholder search/chat routers. All 5 new tests pass (14 total).
24 lines
807 B
Python
24 lines
807 B
Python
# app/api/ingest.py
|
|
"""Ingest job status polling (proxies cf-orch or checks in-memory registry)."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
router = APIRouter(prefix="/api/ingest", tags=["ingest"])
|
|
|
|
# Populated by _run_ingest_background when cf-orch is unavailable
|
|
_task_registry: dict[str, dict] = {}
|
|
|
|
|
|
@router.get("/{task_id}")
|
|
def get_task_status(task_id: str) -> dict:
|
|
# Check in-memory registry first (BackgroundTasks fallback)
|
|
if task_id in _task_registry:
|
|
return _task_registry[task_id]
|
|
|
|
# Try cf-orch
|
|
try:
|
|
from circuitforge_core.tasks import get_task_status as orch_status # type: ignore[import]
|
|
return orch_status(task_id)
|
|
except Exception:
|
|
raise HTTPException(status_code=404, detail="Task not found")
|