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:
@@ -38,6 +38,7 @@ def http_check_single(
|
||||
"""Run HTTP connectivity check for a single prospect."""
|
||||
prospect = prospect_service.get_by_id(db, prospect_id)
|
||||
result = enrichment_service.check_http(db, prospect)
|
||||
db.commit()
|
||||
return HttpCheckResult(**result)
|
||||
|
||||
|
||||
@@ -53,6 +54,7 @@ def http_check_batch(
|
||||
for prospect in prospects:
|
||||
result = enrichment_service.check_http(db, prospect)
|
||||
results.append(HttpCheckBatchItem(domain=prospect.domain_name, **result))
|
||||
db.commit()
|
||||
return HttpCheckBatchResponse(processed=len(results), results=results)
|
||||
|
||||
|
||||
@@ -65,6 +67,7 @@ def tech_scan_single(
|
||||
"""Run technology scan for a single prospect."""
|
||||
prospect = prospect_service.get_by_id(db, prospect_id)
|
||||
profile = enrichment_service.scan_tech_stack(db, prospect)
|
||||
db.commit()
|
||||
return ScanSingleResponse(domain=prospect.domain_name, profile=profile is not None)
|
||||
|
||||
|
||||
@@ -81,6 +84,7 @@ def tech_scan_batch(
|
||||
result = enrichment_service.scan_tech_stack(db, prospect)
|
||||
if result:
|
||||
count += 1
|
||||
db.commit()
|
||||
return ScanBatchResponse(processed=len(prospects), successful=count)
|
||||
|
||||
|
||||
@@ -93,6 +97,7 @@ def performance_scan_single(
|
||||
"""Run PageSpeed audit for a single prospect."""
|
||||
prospect = prospect_service.get_by_id(db, prospect_id)
|
||||
profile = enrichment_service.scan_performance(db, prospect)
|
||||
db.commit()
|
||||
return ScanSingleResponse(domain=prospect.domain_name, profile=profile is not None)
|
||||
|
||||
|
||||
@@ -109,6 +114,7 @@ def performance_scan_batch(
|
||||
result = enrichment_service.scan_performance(db, prospect)
|
||||
if result:
|
||||
count += 1
|
||||
db.commit()
|
||||
return ScanBatchResponse(processed=len(prospects), successful=count)
|
||||
|
||||
|
||||
@@ -121,6 +127,7 @@ def scrape_contacts_single(
|
||||
"""Scrape contacts for a single prospect."""
|
||||
prospect = prospect_service.get_by_id(db, prospect_id)
|
||||
contacts = enrichment_service.scrape_contacts(db, prospect)
|
||||
db.commit()
|
||||
return ContactScrapeResponse(domain=prospect.domain_name, contacts_found=len(contacts))
|
||||
|
||||
|
||||
@@ -154,6 +161,7 @@ def full_enrichment(
|
||||
# Step 5: Compute score
|
||||
db.refresh(prospect)
|
||||
score = scoring_service.compute_score(db, prospect)
|
||||
db.commit()
|
||||
|
||||
return FullEnrichmentResponse(
|
||||
domain=prospect.domain_name,
|
||||
@@ -174,4 +182,5 @@ def compute_scores_batch(
|
||||
):
|
||||
"""Compute or recompute scores for all prospects."""
|
||||
count = scoring_service.compute_all(db, limit=limit)
|
||||
db.commit()
|
||||
return ScoreComputeBatchResponse(scored=count)
|
||||
|
||||
Reference in New Issue
Block a user