Files
geointel/backend/app/services/aoi_operation_worker.py
T
Jens faeb58ef6d
GeoIntel release gates / Compile, test, contracts and builds (push) Successful in 1m49s
GeoIntel release gates / Python and npm vulnerability policy (push) Successful in 21s
GeoIntel release gates / Production AI image, SBOM and container scan (push) Successful in 5m39s
GeoIntel release gates / Deploy exact gated revision to Unraid (push) Failing after 58m43s
Initial public release
2026-08-31 21:56:53 +02:00

39 lines
1.3 KiB
Python

from __future__ import annotations
import asyncio
import logging
from app.db.session import SessionLocal
from app.models import AoiOperation
from app.services.aoi_operation_executor import AoiOperationExecutor
logger = logging.getLogger("geointel.aoi_worker")
class AoiOperationWorker:
@staticmethod
def run_once() -> int:
db = SessionLocal()
try:
rows = db.query(AoiOperation).filter(AoiOperation.status.in_(("queued", "running"))).order_by(AoiOperation.created_at).limit(10).all()
for operation in rows:
try:
AoiOperationExecutor.execute_next(db, operation.project_id, operation.id)
except Exception:
db.rollback()
logger.exception("AOI partition execution failed operation_id=%s", operation.id)
return len(rows)
finally:
db.close()
@staticmethod
async def run(stop_event: asyncio.Event, poll_seconds: float) -> None:
while not stop_event.is_set():
processed = await asyncio.to_thread(AoiOperationWorker.run_once)
if processed == 0:
try:
await asyncio.wait_for(stop_event.wait(), timeout=poll_seconds)
except TimeoutError:
pass