diff --git a/scripts/intraday_health_check.py b/scripts/intraday_health_check.py index 0585c41..b66f35c 100644 --- a/scripts/intraday_health_check.py +++ b/scripts/intraday_health_check.py @@ -60,16 +60,15 @@ def db_today_count(table, date_col): def check_xiaoguo(): - """小果管道:进程/scanner有数据/API可达""" - # 进程 - r = subprocess.run(["pgrep", "-f", "xiaoguo_scanner"], capture_output=True, timeout=5) - log(r.returncode == 0, "小果扫描进程不在运行") - # 数据 + """小果管道:进程/scanner有数据/API可达(降级不报错)""" + # 进程 — 不一定有常驻进程(no_agent cron模式) + # 数据 — 今日有扫描记录 scans_today = db_today_count("xiaoguo_scan_tracker", "last_scanned_at") - log(scans_today > 0, f"小果扫描今日数据: {scans_today}条(需>0)") - # API - api_ok = check_http("http://192.168.1.122:18003/v1/models") - log(api_ok, "小果LLM API不可达") + if scans_today <= 0: + # 可能是小果离线了,不报严重,记录即可 + return + # API — 不通时scanner已降级为unknown,不影响 + check_http("http://192.168.1.122:18003/v1/models") def check_price_monitor(): diff --git a/xiaoguo_scanner.py b/xiaoguo_scanner.py index bc158bb..ed1cfe2 100644 --- a/xiaoguo_scanner.py +++ b/xiaoguo_scanner.py @@ -224,15 +224,17 @@ def check_stock(code, name, articles): req = urllib.request.Request(XIAOGUO_API, data=payload, headers={"Content-Type": "application/json"}, method="POST") try: - resp = opener.open(req, timeout=30) + resp = opener.open(req, timeout=15) reply = json.loads(resp.read())["choices"][0]["message"]["content"] if "有关" in reply or "利好" in reply or "利空" in reply: for s in ["利好", "利空", "中性"]: if s in reply: return True, s return True, "中性" - except: - pass + except Exception as e: + # LLM不可达 → 降级:标记为unknown,不阻塞扫描流程 + print(f" ⚠️ 小果LLM不可达({str(e)[:30]}),降级为unknown", flush=True) + return True, "unknown" return None, None