superbrain-server 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/payload/api.py +4 -38
package/package.json
CHANGED
package/payload/api.py
CHANGED
|
@@ -561,46 +561,12 @@ async def analyze_instagram(request: AnalyzeRequest, token: str = Depends(verify
|
|
|
561
561
|
logger.warning(f"⚠️ [{shortcode}] main.py stderr:\n{stderr[:1000]}")
|
|
562
562
|
|
|
563
563
|
if returncode == 2:
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
logger.info(f"⏰ [{shortcode}] Quota exhausted — queued for automatic retry")
|
|
564
|
+
retry_lines = [l.strip() for l in stdout.splitlines() if l.strip().startswith('?')]
|
|
565
|
+
retry_msg = retry_lines[-1].replace('?', '').strip() if retry_lines else "API quota exhausted or rate limited. Queued for automatic retry in 24 hours."
|
|
566
|
+
logger.info(f"? [{shortcode}] {retry_msg}")
|
|
568
567
|
raise HTTPException(
|
|
569
568
|
status_code=202,
|
|
570
|
-
detail=
|
|
571
|
-
)
|
|
572
|
-
|
|
573
|
-
if returncode != 0:
|
|
574
|
-
# Extract last meaningful error line from stdout for the error message
|
|
575
|
-
error_lines = [l.strip() for l in stdout.splitlines() if l.strip() and ('❌' in l or 'Error' in l or 'failed' in l.lower())]
|
|
576
|
-
error_detail = error_lines[-1] if error_lines else (stderr.strip()[:200] or "Analysis failed")
|
|
577
|
-
logger.error(f"❌ [{shortcode}] Analysis failed: {error_detail}")
|
|
578
|
-
logger.debug(f"[{shortcode}] stdout tail:\n{stdout[-800:]}")
|
|
579
|
-
raise HTTPException(
|
|
580
|
-
status_code=400,
|
|
581
|
-
detail=error_detail
|
|
582
|
-
)
|
|
583
|
-
|
|
584
|
-
logger.info(f"✅ [{shortcode}] Analysis complete! Fetching from database...")
|
|
585
|
-
|
|
586
|
-
# Get result from database — retry up to 4 times in case the SQLite write
|
|
587
|
-
# hasn't flushed yet (race condition between subprocess write and our read).
|
|
588
|
-
analysis = None
|
|
589
|
-
for _attempt in range(4):
|
|
590
|
-
analysis = db.check_cache(shortcode)
|
|
591
|
-
if analysis:
|
|
592
|
-
if _attempt > 0:
|
|
593
|
-
logger.info(f"🔄 [{shortcode}] Found in database on retry {_attempt}")
|
|
594
|
-
break
|
|
595
|
-
if _attempt < 3:
|
|
596
|
-
logger.warning(f"⏳ [{shortcode}] Not in DB yet (attempt {_attempt+1}/4), retrying in 1s…")
|
|
597
|
-
await asyncio.sleep(1)
|
|
598
|
-
|
|
599
|
-
if not analysis:
|
|
600
|
-
logger.error(f"❌ [{shortcode}] Not found in database after 4 attempts!")
|
|
601
|
-
raise HTTPException(
|
|
602
|
-
status_code=500,
|
|
603
|
-
detail="Analysis completed but result not found in database"
|
|
569
|
+
detail=retry_msg
|
|
604
570
|
)
|
|
605
571
|
|
|
606
572
|
# Filter response
|