refactor(prospecting): migrate SVC-006 transaction control to endpoint level
Some checks failed
Some checks failed
Move db.commit() from services to API endpoints and Celery tasks. Services now use db.flush() only; endpoints own the transaction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,12 +56,14 @@ def batch_http_check(self, job_id: int, limit: int = 100):
|
||||
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("batch_http_check job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
|
||||
@@ -111,12 +113,14 @@ def batch_tech_scan(self, job_id: int, limit: int = 100):
|
||||
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("batch_tech_scan job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
|
||||
@@ -166,12 +170,14 @@ def batch_performance_scan(self, job_id: int, limit: int = 50):
|
||||
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("batch_performance_scan job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
|
||||
@@ -220,12 +226,14 @@ def batch_contact_scrape(self, job_id: int, limit: int = 100):
|
||||
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("batch_contact_scrape job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
|
||||
@@ -257,12 +265,14 @@ def batch_score_compute(self, job_id: int, limit: int = 500):
|
||||
job.total_items = count
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("batch_score_compute job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
|
||||
@@ -316,10 +326,12 @@ def full_enrichment(self, job_id: int, prospect_id: int):
|
||||
job.processed_items = 1
|
||||
job.status = "completed"
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - background task owns transaction
|
||||
|
||||
except Exception as e:
|
||||
logger.error("full_enrichment job %d failed: %s", job_id, e, exc_info=True)
|
||||
job.status = "failed"
|
||||
job.error_message = str(e)[:500]
|
||||
job.completed_at = datetime.now(UTC)
|
||||
db.commit() # SVC-006 - persist failure status
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user