From 59f05245d9c1289d3ad3a50b22e125c8757beb5d Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Fri, 2 Jan 2026 12:35:24 -0500 Subject: [PATCH] Fix database method names for import job status updates --- database.py | 16 ++++++++++++++++ serp.py | 14 ++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/database.py b/database.py index 7f36f4e..0c09f97 100644 --- a/database.py +++ b/database.py @@ -373,6 +373,22 @@ class Database: await session.execute(stmt) await session.commit() + async def set_crawl_job_status(self, job_id: int, status: str, error: str = None) -> None: + """Set the status of a crawl job.""" + async with self.session() as session: + values = {'status': status} + if error: + values['error'] = error + if status == 'failed': + values['completed_at'] = datetime.now(timezone.utc).isoformat() + stmt = update(CrawlJob).where(CrawlJob.id == job_id).values(**values) + await session.execute(stmt) + await session.commit() + + async def fail_crawl_job(self, job_id: int, error: str) -> None: + """Mark a crawl job as failed with error message.""" + await self.set_crawl_job_status(job_id, 'failed', error=error) + async def delete_crawl_job(self, job_id: int, purge_data: bool = False) -> Dict[str, Any]: """Delete a crawl job and optionally all associated data. diff --git a/serp.py b/serp.py index 8f7f71e..2ac4446 100644 --- a/serp.py +++ b/serp.py @@ -3806,15 +3806,14 @@ async def complete_resumable_upload(upload_id: str): # Run import in background async def run_import(): try: - await db.update_job_status(job_id, "running") + await db.set_crawl_job_status(job_id, "running") stats = await import_archive_to_db(final_path, job_id) - await db.update_job_stats(job_id, stats) - await db.update_job_status(job_id, "completed") + await db.complete_crawl_job(job_id, stats) final_path.unlink(missing_ok=True) logger.info(f"Sandbox import complete: {stats}") except Exception as e: logger.error(f"Sandbox import failed: {e}") - await db.update_job_status(job_id, "failed", error=str(e)) + await db.fail_crawl_job(job_id, str(e)) task = asyncio.create_task(run_import()) ACTIVE_CRAWL_TASKS[job_id] = task @@ -3871,15 +3870,14 @@ async def upload_archive(file: UploadFile = File(...)): # Run import in background async def run_import(): try: - await db.update_job_status(job_id, "running") + await db.set_crawl_job_status(job_id, "running") stats = await import_archive_to_db(upload_path, job_id) - await db.update_job_stats(job_id, stats) - await db.update_job_status(job_id, "completed") + await db.complete_crawl_job(job_id, stats) upload_path.unlink(missing_ok=True) logger.info(f"Sandbox import complete: {stats}") except Exception as e: logger.error(f"Sandbox import failed: {e}") - await db.update_job_status(job_id, "failed", error=str(e)) + await db.fail_crawl_job(job_id, str(e)) task = asyncio.create_task(run_import()) ACTIVE_CRAWL_TASKS[job_id] = task