Fix discovery refresh: open fresh DB session in background task
The refresh endpoint was passing the request's db session to the background task, which is closed before the task runs — silently doing nothing on every refresh. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -163,7 +163,17 @@ def refresh_discovery(
|
||||
s = db.query(UserSettings).filter_by(user_id=current_user.id).first()
|
||||
regions_str = (s.discovery_regions if s and s.discovery_regions else "US,SE")
|
||||
regions = [r.strip().upper() for r in regions_str.split(",") if r.strip()]
|
||||
background_tasks.add_task(run_full_discovery, db, current_user.id, regions)
|
||||
user_id = current_user.id
|
||||
|
||||
def _run_discovery():
|
||||
from ..database import SessionLocal
|
||||
fresh_db = SessionLocal()
|
||||
try:
|
||||
run_full_discovery(fresh_db, user_id, regions)
|
||||
finally:
|
||||
fresh_db.close()
|
||||
|
||||
background_tasks.add_task(_run_discovery)
|
||||
from .channels import _enrich_missing_task
|
||||
background_tasks.add_task(_enrich_missing_task, 20)
|
||||
return {"detail": "Discovery refresh started"}
|
||||
|
||||
Reference in New Issue
Block a user