From b1cad273308243340a63d9b17bd67de541d6a89b Mon Sep 17 00:00:00 2001 From: furkanyigit34 Date: Thu, 23 Jul 2026 00:55:25 +0300 Subject: [PATCH] =?UTF-8?q?fix(scrape):=200=20=C3=BCr=C3=BCnl=C3=BC=20rapo?= =?UTF-8?q?r=20FAILED=20olarak=20i=C5=9Faretleniyor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ı --- backend/main.py | 7 +++++++ backend/queue_worker.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/backend/main.py b/backend/main.py index 8bb433c..b4d7484 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1865,6 +1865,13 @@ async def create_report( 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 yield f"data: {json_module.dumps({'type': 'info', 'message': '💾 Veritabanına kaydediliyor...', 'progress': 93})}\n\n" await asyncio.sleep(0.5) diff --git a/backend/queue_worker.py b/backend/queue_worker.py index f42e76e..6c1bcf2 100644 --- a/backend/queue_worker.py +++ b/backend/queue_worker.py @@ -329,6 +329,12 @@ class QueueWorker: except Exception as 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 self._mark_completed(db, queue_id, report_id) log.info(f"Task {queue_id} completed: report_id={report_id}, products={results['total_products']}")