Backend- file ingestion API Updates
This commit is contained in:
29
app/main.py
29
app/main.py
@@ -22,6 +22,7 @@ from fastapi.responses import FileResponse
|
||||
from app.infrastructure.persistence import restore_bundled_assets
|
||||
from app.infrastructure.settings import (
|
||||
API_CORS_ORIGINS,
|
||||
BATCH_AUTO_RESUME,
|
||||
BRAND_SYNC_INTERVAL_SECONDS,
|
||||
cleaned_env_names,
|
||||
)
|
||||
@@ -30,7 +31,7 @@ from app.api.routers import health, brands, search, suggest, chat, catalog, syst
|
||||
from app.api.routers import stores, discounts, analytics as store_analytics, trending, recommendations, store_admin
|
||||
from app.api.routers import nutrition, nutrition_admin, upload
|
||||
from app.api.routers import auth, user_products, admin_train, mcp_info
|
||||
from app.api.routers import store_catalog
|
||||
from app.api.routers import store_catalog, batch_catalog
|
||||
from app.services.store_db import ensure_store_intelligence_schema
|
||||
from app.services.nutrition_db import ensure_nutrition_schema
|
||||
|
||||
@@ -82,6 +83,31 @@ async def lifespan(_app: FastAPI):
|
||||
except Exception as e:
|
||||
logger.warning("Could not restore bundled assets: %s", e)
|
||||
|
||||
# Cheap, and it must happen before anyone can press Resume: a batch that a
|
||||
# restart cut short is still marked "running" on disk, and until it is
|
||||
# reconciled the UI shows it as in flight with nothing behind it. This only
|
||||
# rewrites manifests - it deliberately starts no work. See
|
||||
# batch_ingest.scan_interrupted() for why auto-resume is not the default.
|
||||
try:
|
||||
from app.core.batch_ingest import scan_interrupted
|
||||
|
||||
interrupted = scan_interrupted()
|
||||
if interrupted:
|
||||
logger.info("Marked %d interrupted catalog batch(es).", len(interrupted))
|
||||
if interrupted and BATCH_AUTO_RESUME:
|
||||
# Opt-in only. Importing the worker here rather than at module
|
||||
# scope keeps the queue and its thread out of a boot that never
|
||||
# needs them.
|
||||
from app.core import batch_worker
|
||||
|
||||
for batch_id in interrupted:
|
||||
try:
|
||||
batch_worker.submit(batch_id)
|
||||
except Exception as exc: # noqa: BLE001 - a full queue is not fatal
|
||||
logger.warning("Could not auto-resume batch %s: %s", batch_id, exc)
|
||||
except Exception as e:
|
||||
logger.warning("Could not reconcile interrupted catalog batches: %s", e)
|
||||
|
||||
def _async_init():
|
||||
try:
|
||||
ensure_store_intelligence_schema()
|
||||
@@ -266,6 +292,7 @@ app.include_router(nutrition.router, prefix="/api")
|
||||
app.include_router(nutrition_admin.router, prefix="/api")
|
||||
app.include_router(upload.router, prefix="/api")
|
||||
app.include_router(store_catalog.router, prefix="/api")
|
||||
app.include_router(batch_catalog.router, prefix="/api")
|
||||
app.include_router(mcp_info.router, prefix="/api")
|
||||
|
||||
# MCP lives outside /api on purpose: it is a protocol endpoint for AI clients,
|
||||
|
||||
Reference in New Issue
Block a user