fix: bugs-01

This commit is contained in:
2026-03-12 19:57:30 +08:00
parent 9e609f89a3
commit ce537bb3dc
7 changed files with 62 additions and 37 deletions

View File

@@ -24,6 +24,24 @@ def process_image_ocr(self, image_id: str):
_run_async(process_image_ocr_async(image_id))
async def process_images_ocr_batch_async(image_ids: list[str], max_concurrency: int) -> None:
"""Process many images with bounded OCR concurrency."""
if not image_ids:
return
concurrency = max(1, max_concurrency)
semaphore = asyncio.Semaphore(concurrency)
async def _run_one(image_id: str) -> None:
async with semaphore:
try:
await process_image_ocr_async(image_id)
except Exception:
# Keep batch processing alive even if one image fails.
logger.exception("Image %s OCR failed in batch", image_id)
await asyncio.gather(*[_run_one(image_id) for image_id in image_ids])
async def process_image_ocr_async(image_id_str: str):
from app.core.database import async_session_factory
from sqlalchemy import delete