feat: Add method to get extractions by status and implement user info retrieval in extraction service
Some checks failed
Backend CI / lint (push) Failing after 4m53s
Backend CI / test (push) Failing after 4m31s

This commit is contained in:
JSC
2025-08-24 13:24:48 +02:00
parent 28faca55bc
commit 16eb789539
5 changed files with 177 additions and 10 deletions

View File

@@ -35,6 +35,9 @@ class ExtractionProcessor:
logger.warning("Extraction processor is already running")
return
# Reset any stuck extractions from previous runs
await self._reset_stuck_extractions()
self.shutdown_event.clear()
self.processor_task = asyncio.create_task(self._process_queue())
logger.info("Started extraction processor")
@@ -179,6 +182,46 @@ class ExtractionProcessor:
self.max_concurrent,
)
async def _reset_stuck_extractions(self) -> None:
"""Reset any extractions stuck in 'processing' status back to 'pending'."""
try:
async with AsyncSession(engine) as session:
extraction_service = ExtractionService(session)
# Get all extractions stuck in processing status
stuck_extractions = (
await extraction_service.extraction_repo.get_by_status("processing")
)
if not stuck_extractions:
logger.info("No stuck extractions found to reset")
return
reset_count = 0
for extraction in stuck_extractions:
try:
await extraction_service.extraction_repo.update(
extraction, {"status": "pending", "error": None}
)
reset_count += 1
logger.info(
"Reset stuck extraction %d from processing to pending",
extraction.id,
)
except Exception:
logger.exception(
"Failed to reset extraction %d", extraction.id
)
await session.commit()
logger.info(
"Successfully reset %d stuck extractions from processing to pending",
reset_count,
)
except Exception:
logger.exception("Failed to reset stuck extractions")
def get_status(self) -> dict:
"""Get the current status of the extraction processor."""
return {