异常浮窗+统一告警通道+冷却1小时: alert_logger统一异常写入(alerts.json+history.log+XMPP), 前端右上角浮动异常区(自动展开5秒折叠,只显示active), price_monitor接入异常钩子(重评失败/拉取失败/DB同步), 冷却30分->1小时+15分5%突发例外

This commit is contained in:
xxm
2026-08-13 00:35:53 +08:00
parent cf5af7e799
commit ea77bd5afd
2 changed files with 129 additions and 1 deletions
+25 -1
View File
@@ -9,6 +9,7 @@ import sqlite3
from datetime import datetime
from mo_data import read_decisions
from alert_logger import record_alert, clear_alert
BREACH_PATH = "/home/hmo/.hermes/zone_breach.json"
STATE_PATH = "/home/hmo/.hermes/price_trigger_state.json"
@@ -105,6 +106,10 @@ def fetch_all_prices(codes):
text = r.read().decode("gbk")
except Exception as e:
print(f"⚠️ 批量拉取失败: {e}", file=sys.stderr)
try:
record_alert(level="warning", source="price_monitor", title="批量拉取失败", detail=str(e)[:200])
except Exception:
pass
return {}
results = {}
@@ -149,6 +154,10 @@ def refresh_data_prices():
conn.close()
except Exception as e:
print(f"⚠️ 从DB读代码失败: {e}", file=sys.stderr)
try:
record_alert(level="warning", source="price_monitor", title="读取持仓失败", detail=str(e)[:200])
except Exception:
pass
return 0
if not all_codes:
@@ -295,6 +304,10 @@ def refresh_data_prices():
except Exception: pass
conn = None
print(f"⚠️ DB同步异常: {e}", file=sys.stderr)
try:
record_alert(level="error", source="price_monitor", title="DB同步异常", detail=str(e)[:200])
except Exception:
pass
break
else:
# for-else: loop exhausted without break
@@ -537,7 +550,10 @@ def run_once(round_label=""):
record_event(code, name, "swing_re", price, str(_ma10))
_push_action("波段再进", f"📈 {name}({code}) {price} 收回MA10({_ma10:.2f})且突破前一日高点 → 波段再进,可接回")
except Exception as _e:
pass
try:
record_alert(level="warning", source="price_monitor", title="波段检测异常", detail=str(_e)[:200], code=code)
except Exception:
pass
# 时间预算检查:如果超时,跳过重评只做状态记录
_budget_low = (time.time() - start) > TIME_BUDGET
@@ -578,6 +594,10 @@ def run_once(round_label=""):
outputs.append(f" 📨 止损重评→已推送Dad: {action}")
except Exception as e:
outputs.append(f" ⚠️ 止损重评失败: {e}")
try:
record_alert(level="error", source="price_monitor", title="止损重评失败", detail=str(e)[:200], code=code)
except Exception:
pass
else:
extra = ""
if "_price" in key:
@@ -626,6 +646,10 @@ def run_once(round_label=""):
outputs.append(f" 📋 本地日志(不推): {reason}")
except Exception as e:
outputs.append(f" ⚠️ 区间重评失败: {e}")
try:
record_alert(level="error", source="price_monitor", title="区间重评失败", detail=str(e)[:200], code=code)
except Exception:
pass
state[code][key] = True
state_updated = True