diff --git a/app/beauty_main.py b/app/beauty_main.py index 54d4aeb..1b85130 100644 --- a/app/beauty_main.py +++ b/app/beauty_main.py @@ -218,6 +218,7 @@ async def prescreen_batch(body: dict): from app.prescreener import prescreen_domains, classify_with_deepseek, DEEPSEEK_BATCH_SIZE + # Phase 1: HTTP check — runs synchronously, finishes in ~30-90s, saves immediately. results = await prescreen_domains(domains_list) await save_prescreen_results(results) @@ -227,18 +228,26 @@ async def prescreen_batch(body: dict): counts[s] = counts.get(s, 0) + 1 live = [r for r in results if r.get("prescreen_status") == "live"] - classified = 0 + + # Phase 2: DeepSeek classification — fires in the background so the HTTP + # response is returned immediately. Results are saved async; the Browse + # table will show niche/type once the background task completes. if live: - batches = [live[i:i + DEEPSEEK_BATCH_SIZE] for i in range(0, len(live), DEEPSEEK_BATCH_SIZE)] - all_cls: list = [] - for i, batch in enumerate(batches): - if i > 0: - await asyncio.sleep(3) - cls = await classify_with_deepseek(batch) - all_cls.extend(cls) - if all_cls: - await save_prescreen_results(all_cls) - classified = len(all_cls) + async def _classify_bg(items: list) -> None: + try: + batches = [items[i:i + DEEPSEEK_BATCH_SIZE] + for i in range(0, len(items), DEEPSEEK_BATCH_SIZE)] + for i, batch in enumerate(batches): + if i > 0: + await asyncio.sleep(3) + cls = await classify_with_deepseek(batch) + if cls: + await save_prescreen_results(cls) + logger.info("Prescreen BG: classified %d domains", len(cls)) + except Exception as e: + logger.error("Prescreen BG classification failed: %s", e) + + asyncio.create_task(_classify_bg(live)) return { "total": len(domains_list), @@ -246,7 +255,8 @@ async def prescreen_batch(body: dict): "parked": counts.get("parked", 0), "redirect": counts.get("redirect", 0), "dead": counts.get("dead", 0), - "classified": classified, + "error": counts.get("error", 0), + "classifying": len(live), # niche/type arrives shortly via background task } diff --git a/app/static/beauty/index.html b/app/static/beauty/index.html index 3b88147..1af2d6d 100644 --- a/app/static/beauty/index.html +++ b/app/static/beauty/index.html @@ -559,7 +559,7 @@ function app() { try { const chunks = []; for (let i=0; ir.json()); totals.live += d.live||0; totals.dead += d.dead||0; totals.parked += d.parked||0; totals.redirect += d.redirect||0; - totals.classified += d.classified||0; + totals.error += d.error||0; totals.classifying += d.classifying||0; } - this.notify(`✅ ${totals.live} live · ☠ ${totals.dead} dead · 🅿 ${totals.parked} parked · 🏷 ${totals.classified} classified`, 'success'); + const cls = totals.classifying > 0 ? ` · 🏷 classifying ${totals.classifying} in background` : ''; + this.notify(`✅ ${totals.live} live · ☠ ${totals.dead} dead · 🅿 ${totals.parked} parked${cls}`, 'success'); this.selected = []; await this.loadDomains(); } catch(e) { this.notify('Pre-screen failed: '+e.message, 'error'); }