diff --git a/backend/main.py b/backend/main.py index 81ca0fc..1fa84e2 100644 --- a/backend/main.py +++ b/backend/main.py @@ -3699,8 +3699,9 @@ def _enrich_build_product_info(all_products): return info -def _enrich_report_task(report_id: int): +def _enrich_report_task(report_id: int, progress_cb=None): import time + import threading db = SessionLocal() try: enrichment_progress[report_id] = {"status": "running", "step": "init", "done": 0, "total": 2} @@ -3718,9 +3719,28 @@ def _enrich_report_task(report_id: int): # _save_json(f"{base_dir}/reviews.json", rev_payload) # time.sleep(0.1) - # 2) Social Proof + # 2) Social Proof — monitor internal batch progress and relay to queue enrichment_progress[report_id] = {"status": "running", "step": "social", "done": 0, "total": 1} + stop_monitor = threading.Event() + if progress_cb: + def _monitor_social(): + progress_key = f"social_{report_id}" + last_queue_pct = 95 + while not stop_monitor.wait(30): + ep = enrichment_progress.get(progress_key) or {} + done = ep.get("processed", 0) + total = ep.get("total", 0) or 1 + queue_pct = 96 + min(3, int((done / total) * 4)) + if queue_pct > last_queue_pct: + last_queue_pct = queue_pct + try: + progress_cb(queue_pct, f"Sosyal kanit: {done}/{total} urun") + except Exception: + pass + threading.Thread(target=_monitor_social, daemon=True).start() + soc_payload = social_proof(report_id, refresh=True, db=db) or {} + stop_monitor.set() # ürün isimlerini detaylara iliştir if soc_payload and soc_payload.get("details"): details = soc_payload["details"] diff --git a/backend/queue_worker.py b/backend/queue_worker.py index 3cba263..8a56946 100644 --- a/backend/queue_worker.py +++ b/backend/queue_worker.py @@ -308,7 +308,11 @@ class QueueWorker: self._update_progress(db, queue_id, 95, "Sosyal kanit verileri toplanıyor...") try: from main import _enrich_report_task - _enrich_report_task(report_id) + + def _progress_cb(p: int, m: str): + self._update_progress(db, queue_id, p, m) + + _enrich_report_task(report_id, progress_cb=_progress_cb) log.info(f"Enrichment completed for report {report_id}") except Exception as e: log.warning(f"Enrichment failed (non-critical): {e}")