341d0c6f38
Backend (ruff): - F821: Add TYPE_CHECKING imports for Vehicle, Contact, File in models (file.py, retouch.py, sale.py, vehicle.py) - E741: Rename ambiguous variable to / (copilot_service.py, price_compare_service.py, openrouter.py) - F841: Remove unused variable in sale_service.py Frontend (ESLint): - react/no-unescaped-entities: Escape quotes in ContractPreview.tsx - @next/next/no-img-element: Replace <img> with <Image> from next/image (FileGallery.tsx, FileList.tsx, FilePreview.tsx, BeforeAfterSlider.tsx) Tests: 392 backend passed, 112 frontend passed, next build successful
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""Async OCR processing task using background tasks.
|
|
|
|
In production this would use Redis Queue (RQ) or Celery.
|
|
For now, we use FastAPI BackgroundTasks to trigger async processing.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import uuid
|
|
|
|
|
|
from app.database import async_session_factory
|
|
from app.services.ocr_service import process_ocr
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def run_ocr_processing(result_id: uuid.UUID) -> None:
|
|
"""Background task: process OCR result asynchronously.
|
|
|
|
Creates its own DB session (independent of the request session)
|
|
so the HTTP response can return immediately.
|
|
"""
|
|
async with async_session_factory() as session:
|
|
try:
|
|
await process_ocr(session, result_id)
|
|
await session.commit()
|
|
logger.info("OCR processing completed for result %s", result_id)
|
|
except Exception as exc:
|
|
await session.rollback()
|
|
logger.error("OCR background task failed for %s: %s", result_id, exc)
|
|
raise
|
|
finally:
|
|
await session.close()
|