diff --git a/docs/cron-to-xmpp-restore-20260811.md b/docs/cron-to-xmpp-restore-20260811.md new file mode 100644 index 00000000..70b3c3f8 --- /dev/null +++ b/docs/cron-to-xmpp-restore-20260811.md @@ -0,0 +1,127 @@ +# cron_to_xmpp 双通道清理 — 恢复说明 + +> 创建:2026-08-11 | 操作人:小小莫 | 决策人:老莫 +> 状态:✅ 已执行(系统 crontab 版已停,hermes jobs 版保留) +> 对应审计项:system-audit-20260810.md §十「cron_to_xmpp 双通道」 + +--- + +## 一、背景:什么是双通道 + +`cron_to_xmpp.py`(智能 cron 报告推送)被**两个独立的调度系统**同时调度: + +| 调度系统 | 调度配置 | 状态 | +|---------|---------|------| +| **系统 crontab** | `*/2 * * * *`(每 2 分钟,全天)| 🛑 2026-08-11 已停 | +| **hermes jobs.json** | `*/5 9-16 * * 1-5`(每 5 分钟,交易日盘中)| ✅ 保留(正常)| + +两处调用的是**同一份脚本文件**(硬链接,md5 相同),非两个版本。 + +### 脚本职责 +扫描 cron 输出目录 → 找到 LLM 生成的报告(有实质内容)→ 推送到 XMPP(老爸微信)。 +规则:跳过纯脚本输出、跳过 [SILENT]、正文 <20 字不推、journal 去重(防重复推送)。 + +--- + +## 二、停用了什么(2026-08-11) + +### 停用 1:cron_to_xmpp(crontab 版) +```bash +# 原命令(已在 crontab 中注释保留) +*/2 * * * * cd /home/hmo/MoFin/deploy/profile-scripts && python3 cron_to_xmpp.py >> /home/hmo/.cron_to_xmpp.log 2>&1 +``` + +**停用理由**:hermes jobs.json 版(`cron报告推XMPP-每5分`,id=f948702cf5de)功能完整: +- ✅ 同一脚本(md5 一致) +- ✅ 有 journal 去重(不会重复推送) +- ✅ 有状态追踪(last_status/last_run_at) +- ✅ 交易日限定(9-16 点,周末不跑) +- crontab 版每次空转(日志"推送0份"——报告已被 hermes 版先消费) + +### 停用 2:session_to_cron_bridge(crontab 版) +```bash +# 原命令(已在 crontab 中注释保留) +*/2 * * * * cd /home/hmo/web-dashboard && python3 session_to_cron_bridge.py >> /home/hmo/.session_bridge.log 2>&1 +``` + +**停用理由**:它服务的目录 `.hermes/cron/output/`(顶层 mohe 旧 cron 输出)**已停摆**(顶层 jobs.json 7/23 后无更新,38991 个历史文件,8/1 后无新写入)。日志持续"写入0份新报告"——空转。 +**当前活跃通道**:`~/.hermes/profiles/position-analyst/cron/output/`(hermes jobs 直写,不经 bridge)。 + +> ⚠️ **重要**:session_to_cron_bridge **没有 hermes jobs 替代**,它是纯 crontab 依赖。 +> 若未来恢复顶层(mohe)cron 调度,需同步恢复此 bridge。 + +--- + +## 三、备份位置(恢复依据) + +| 备份 | 位置 | +|------|------| +| **完整 crontab 备份** | `/home/hmo/.backups/crontab.bak_20260811_cron_to_xmpp`(53 行,含注释)| +| **脚本本体** | `/home/hmo/MoFin/deploy/profile-scripts/cron_to_xmpp.py`(= hermes scripts 硬链接)| +| **bridge 本体** | `/home/hmo/MoFin/deploy/profile-scripts/session_to_cron_bridge.py`(= web-dashboard 硬链接)| +| **hermes 版 job 配置** | `~/.hermes/profiles/position-analyst/cron/jobs.json`(id=f948702cf5de)| +| **推送日志** | `/home/hmo/.cron_to_xmpp.log` / `/home/hmo/.session_bridge.log` | +| **去重 journal** | `~/.hermes/cron/.relay_journal.json`(两版共享,勿删)| + +--- + +## 四、如何恢复 + +### 场景 A:hermes 版挂了,需要 crontab 版兜底 + +```bash +# 1. 取消 crontab 中 cron_to_xmpp 那行的注释(去掉行首 #) +crontab -e +# 找到这行,删掉行首 "# [2026-08-11停] ..." 注释前缀,恢复为: +*/2 * * * * cd /home/hmo/MoFin/deploy/profile-scripts && python3 cron_to_xmpp.py >> /home/hmo/.cron_to_xmpp.log 2>&1 + +# 2. 验证生效 +crontab -l | grep cron_to_xmpp +tail -5 /home/hmo/.cron_to_xmpp.log # 应看到新的运行记录 +``` + +### 场景 B:顶层(mohe)cron 恢复,需要 session_to_cron_bridge + +```bash +# 1. 确认顶层 cron 是否真的恢复(有活跃 job) +ls -la /home/hmo/.hermes/cron/jobs.json # mtime 应更新 +# 2. 确认顶层 output 有新写入 +find /home/hmo/.hermes/cron/output -type f -newermt '7 days ago' | head +# 3. 若以上确认恢复,则取消 bridge 注释: +crontab -e +*/2 * * * * cd /home/hmo/web-dashboard && python3 session_to_cron_bridge.py >> /home/hmo/.session_bridge.log 2>&1 +``` + +### 场景 C:完全回滚(两条都恢复) + +```bash +# 直接用备份覆盖 crontab(恢复全部条目) +crontab /home/hmo/.backups/crontab.bak_20260811_cron_to_xmpp +crontab -l | grep -E 'cron_to_xmpp|session_to_cron' # 应显示两条 */2 原命令 +``` + +--- + +## 五、验证清单(停用后确认推送正常) + +```bash +# 1. hermes 版仍在跑 +python3 -c "import json; d=json.load(open('/home/hmo/.hermes/profiles/position-analyst/cron/jobs.json')); jobs=d['jobs']; [print(j['name'], j.get('last_status')) for j in jobs if 'cron_to_xmpp' in str(j.get('script',''))]" +# → 应显示: cron报告推XMPP-每5分 ok + +# 2. crontab 版已停(无活跃条目) +crontab -l | grep 'cron_to_xmpp.py >>' | grep -v '^#' # → 应为空 + +# 3. 推送仍工作(等一次 hermes 版运行后查 journal) +ls -la /home/hmo/.hermes/cron/.relay_journal.json # mtime 持续更新 +``` + +--- + +## 六、注意事项 + +1. **journal 是共享的**:`.relay_journal.json` 被两版共用,停 crontab 版不影响去重状态 +2. **日志文件保留**:`.cron_to_xmpp.log` 不再追加(停用),但历史记录保留 +3. **勿删脚本**:`cron_to_xmpp.py` 和 `session_to_cron_bridge.py` 本体保留(hermes 版仍用前者) +4. **hermes 版 job 勿动**:`cron报告推XMPP-每5分`(id=f948702cf5de)是当前唯一活跃入口 +5. **若发现漏推**:先查 journal 是否正常、再查 hermes 版 job 状态,最后才考虑恢复 crontab 版