from __future__ import annotations from fastapi import APIRouter, BackgroundTasks from backend.app.scraper.runner import scrape_all, scrape_product router = APIRouter(prefix="/scrape", tags=["scrape"]) @router.post("/product/{product_id}") def trigger_single(product_id: int, background_tasks: BackgroundTasks): # on délègue le vrai travail à un background task rapide background_tasks.add_task(scrape_product, product_id) return {"statut": "planifie", "cible": product_id} @router.post("/all") def trigger_all(background_tasks: BackgroundTasks): background_tasks.add_task(scrape_all) return {"statut": "planifie_tout"}