diff --git a/src/api.py b/src/api.py index 6634e0b..910167c 100644 --- a/src/api.py +++ b/src/api.py @@ -188,13 +188,21 @@ async def chat_suggestions(q: str = ""): # --- Ingress Endpoints --- +async def process_ingress_background(url: str): + """Background task to process ingress.""" + try: + await ingress_pipeline.process(url) + except Exception as e: + print(f"Ingress error for {url}: {e}") + + @app.post("/ingress", response_model=IngressResponse) async def ingress(request: IngressRequest, background_tasks: BackgroundTasks): """ Process an external article URL through the ingress pipeline. - This scrapes the article, analyzes it for wiki relevance, - finds matching existing articles, and generates draft articles. + Returns immediately and processes in the background. + Check /review endpoint for results. """ if not ingress_pipeline: raise HTTPException( @@ -202,20 +210,18 @@ async def ingress(request: IngressRequest, background_tasks: BackgroundTasks): detail="Ingress pipeline not initialized. Run indexing first.", ) - try: - result = await ingress_pipeline.process(str(request.url)) + # Process in background to avoid Cloudflare timeout + background_tasks.add_task(process_ingress_background, str(request.url)) - return IngressResponse( - status="success", - message="Article processed successfully", - scraped_title=result.scraped.title, - topics_found=len(result.analysis.get("main_topics", [])), - wiki_matches=len(result.wiki_matches), - drafts_generated=len(result.draft_articles), - queue_file=result.timestamp, - ) - except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) + return IngressResponse( + status="processing", + message="Article submitted for processing. Check the Review tab for results.", + scraped_title=None, + topics_found=0, + wiki_matches=0, + drafts_generated=0, + queue_file=None, + ) # --- Review Queue Endpoints ---