fix: dashboard monitor checks local crontab + dev-spec adds Linux-first deployment rule

This commit is contained in:
hmo
2026-07-19 09:24:03 +08:00
parent d6950b0982
commit 0ed048c327
2 changed files with 7 additions and 27 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
# 开发规范 # 开发规范
> 版本: v2.2 | 更新: 2026-07-17 > 版本: v2.3 | 更新: 2026-07-19
--- ---
@@ -14,6 +14,7 @@
2. **部署必验** — 部署后不打开 K Tab 验证 = 部署未完成 2. **部署必验** — 部署后不打开 K Tab 验证 = 部署未完成
3. **不可见即不存在** — 组件不在 dashboard 中显示 = 等于没部署。离线不告警 = 监控缺陷 3. **不可见即不存在** — 组件不在 dashboard 中显示 = 等于没部署。离线不告警 = 监控缺陷
4. **实现后同步 Spec** — 每轮开发完毕后,必须将 specs/{module}.json 更新为与实际实现一致的状态。文档过期 = 等于没写 4. **实现后同步 Spec** — 每轮开发完毕后,必须将 specs/{module}.json 更新为与实际实现一致的状态。文档过期 = 等于没写
5. **部署目标即验收标准** — 所有代码必须以部署目标环境(Linux 246)为基准编写和测试。在本地开发机器(Windows/Mac)上跑通不等于验收通过。部署脚本、系统工具(`systemctl`/`crontab`/`ss`/`df`)、Python 版本、文件路径等都必须匹配 246 的实际环境。禁止使用 Windows 专属 API`tasklist``netstat``schtasks``wmic`)在 246 部署的代码中
--- ---
+5 -26
View File
@@ -844,37 +844,16 @@ def api_monitor():
status = "error" status = "error"
result["tasks"].append({"name": name, "status": status}) result["tasks"].append({"name": name, "status": status})
else: else:
# Linux: SSH 到 Windows 查 schtasks(输出可能是 GBK # Linux: 直接检查本地 crontab(不在 Windows 上跑了
win_host = os.environ.get("WINDOWS_HOST", "192.168.1.16")
for name in expected_tasks: for name in expected_tasks:
try: try:
r = subprocess.run( r = subprocess.run(["crontab", "-l"], capture_output=True, text=True, timeout=5)
["ssh", "-o", "StrictHostKeyChecking=no", "-o", "ConnectTimeout=5", if name in r.stdout:
"-o", "BatchMode=yes", f"hmo@{win_host}", result["tasks"].append({"name": name, "status": "cron_ok"})
f"schtasks /Query /TN {name} /FO CSV /NH"],
capture_output=True, timeout=10
)
# 先看去重定向码:非0 = 任务不存在
if r.returncode != 0:
result["tasks"].append({"name": name, "status": "not_deployed"})
continue
# 尝试解码输出(Windows schtasks 默认 GBK,也试试 UTF-8
out = ""
for enc in ["utf-8", "gbk", "gb2312", "cp936"]:
try:
out = r.stdout.decode(enc)
break
except UnicodeDecodeError:
continue
if name in out:
if "就绪" in out or "Ready" in out or "Running" in out:
result["tasks"].append({"name": name, "status": "schtasks_ok"})
else:
result["tasks"].append({"name": name, "status": "schtasks_unknown", "raw": out.strip()})
else: else:
result["tasks"].append({"name": name, "status": "not_deployed"}) result["tasks"].append({"name": name, "status": "not_deployed"})
except Exception as e: except Exception as e:
result["tasks"].append({"name": name, "status": "not_deployed", "note": f"SSH到Windows失败: {str(e)[:60]}"}) result["tasks"].append({"name": name, "status": "not_deployed", "note": str(e)[:60]})
return jsonify(result) return jsonify(result)