fix(scrape): 0 ürünlü rapor FAILED olarak işaretleniyor
All checks were successful
ciromarket-backend-build-and-deploy / build (push) Successful in 2m8s

Ne yaptık:
- SSE endpoint: tüm subcategory'ler başarısız olursa type=failed event yield et, DB'ye kaydetme
- queue_worker: total_products==0 ve en az 1 kategori denendiyse _mark_failed() çağır

Neden yaptık:
- Trendyol rate limit (HTTP 556) durumunda tüm subcategory'ler success=False dönüyor
- Sistem bunu hata olarak değil "0 ürünlü başarılı rapor" olarak kaydediyordu
- Kullanıcıya "Bu kategoride ürün bulunamadı / Farklı kategori deneyin" mesajı çıkıyordu — tamamen yanıltıcı
- Artık FAILED → Spring Boot CiromarketSseConsumer/QueuePoller → SellerX DB FAILED → frontend hata mesajı
This commit is contained in:
2026-07-23 00:55:25 +03:00
parent 2b0e83f2eb
commit b1cad27330
2 changed files with 13 additions and 0 deletions

View File

@@ -1865,6 +1865,13 @@ async def create_report(
await asyncio.to_thread(_write_json, json_filename, combined_data) await asyncio.to_thread(_write_json, json_filename, combined_data)
# Tüm subcategory'ler başarısız olduysa raporu kaydetme, FAILED döndür
successful_count = sum(1 for d in results.get("details", []) if d.get("success"))
total_attempted = len(results.get("details", []))
if total_attempted > 0 and successful_count == 0:
yield f"data: {json_module.dumps({'type': 'failed', 'reason': 'scrape_failed', 'message': 'Trendyol geçici olarak kullanılamıyor. Lütfen birkaç dakika bekleyip tekrar deneyin.', 'progress': 100})}\n\n"
return
# Save to database # Save to database
yield f"data: {json_module.dumps({'type': 'info', 'message': '💾 Veritabanına kaydediliyor...', 'progress': 93})}\n\n" yield f"data: {json_module.dumps({'type': 'info', 'message': '💾 Veritabanına kaydediliyor...', 'progress': 93})}\n\n"
await asyncio.sleep(0.5) await asyncio.sleep(0.5)

View File

@@ -329,6 +329,12 @@ class QueueWorker:
except Exception as e: except Exception as e:
log.warning(f"Enrichment failed (non-critical): {e}") log.warning(f"Enrichment failed (non-critical): {e}")
# Tüm subcategory'ler başarısız olduysa FAILED işaretle
if results.get("total_products", 0) == 0 and len(results.get("details", [])) > 0:
self._mark_failed(db, queue_id, "Trendyol geçici olarak kullanılamıyor. Lütfen birkaç dakika bekleyip tekrar deneyin.")
log.warning(f"Task {queue_id} scrape_failed: 0 products from {len(results['details'])} categories")
return
# Mark COMPLETED # Mark COMPLETED
self._mark_completed(db, queue_id, report_id) self._mark_completed(db, queue_id, report_id)
log.info(f"Task {queue_id} completed: report_id={report_id}, products={results['total_products']}") log.info(f"Task {queue_id} completed: report_id={report_id}, products={results['total_products']}")