Group search results by owner; auto-resume stuck pending documents

This commit is contained in:
Krikorios
2026-05-07 21:59:29 +03:00
parent 631a4c3e3d
commit 60eb58cc9f
6 changed files with 80 additions and 13 deletions
+18
View File
@@ -38,6 +38,24 @@ async def lifespan(app: FastAPI):
cleanup_expired_sessions()
except Exception:
pass
# Resume any documents that were left in 'pending' state from a previous run
# (e.g. server restart killed the background extraction task).
try:
import asyncio
from database.connection import get_db
from services.extractor import get_default_provider
from routers.upload import _extract_and_save
default_provider = get_default_provider()
with get_db() as conn:
stuck = conn.execute(
"SELECT id, image_path, provider FROM documents WHERE status='pending'"
).fetchall()
for row in stuck:
provider = row["provider"] or default_provider
asyncio.create_task(_extract_and_save(row["id"], row["image_path"], provider))
except Exception:
pass
yield