mirror of
https://github.com/nethunterzist/trendyol-analiz
synced 2026-08-29 21:38:00 +00:00
fix(ciromarket): sosyal kanit asamasinda queue progress guncelle
Ne yaptik: - _enrich_report_task fonksiyonu progress_cb parametresi aldi - social_proof calismasi sirasinda daemon monitor thread baslatiyor - Her 30 saniyede enrichment_progress izleyip queue'yu 96-99% araliginda guncelliyor - queue_worker.py: _progress_cb lambda ile self._update_progress bagladi Neden yaptik: - Sosyal kanit asamasi (5000+ urun, ~12 dk) boyunca progress yuzde 95'te donuyordu, kullanici rapor takildi saniyordu. - Artik UI gercek ilerlemeyi 96-99% araliginda gosterecek.
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user