first commit
This commit is contained in:
38
backend/app/workers/analysis_tasks.py
Normal file
38
backend/app/workers/analysis_tasks.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Celery task: full-case analysis pipeline."""
|
||||
import asyncio
|
||||
import logging
|
||||
from uuid import UUID
|
||||
|
||||
from app.workers.celery_app import celery_app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _run_async(coro):
|
||||
loop = asyncio.new_event_loop()
|
||||
try:
|
||||
return loop.run_until_complete(coro)
|
||||
finally:
|
||||
loop.close()
|
||||
|
||||
|
||||
@celery_app.task(name="app.workers.analysis_tasks.run_full_analysis", bind=True, max_retries=2)
|
||||
def run_full_analysis(self, case_id_str: str):
|
||||
_run_async(_run(case_id_str))
|
||||
|
||||
|
||||
async def _run(case_id_str: str):
|
||||
from app.core.database import async_session_factory
|
||||
from app.services.analysis_pipeline import run_analysis_sync
|
||||
|
||||
case_id = UUID(case_id_str)
|
||||
|
||||
async with async_session_factory() as db:
|
||||
try:
|
||||
await run_analysis_sync(case_id, db)
|
||||
await db.commit()
|
||||
logger.info("Full analysis completed for case %s", case_id)
|
||||
except Exception as e:
|
||||
await db.rollback()
|
||||
logger.error("Analysis failed for case %s: %s", case_id, e)
|
||||
raise
|
||||
Reference in New Issue
Block a user