edit | blame | history | raw

推送流程优化验证清单

创建的脚本

✓ 1. scripts/is_trading_day.py(交易日判断)

  • [x] 可以判断今天是否是交易日
  • [x] 考虑周末(周六周日)
  • [x] 考虑节假日(支持节假日列表)
  • [x] 返回True/False
  • [x] 有清晰的日志输出
  • [x] 可独立运行

✓ 2. scripts/auto_push_system.py(自动化推送系统)

  • [x] 自动加载最新市场数据
  • [x] 计算α因子得分
  • [x] 执行α因子选股
  • [x] 检查持仓风险(止盈/止损)
  • [x] 评估换仓决策
  • [x] 生成完整推送内容
  • [x] 自动发送飞书推送
  • [x] 记录推送历史
  • [x] 返回值:成功/失败,报告内容
  • [x] 可独立运行
  • [x] 完整的日志记录
  • [x] 异常处理

✓ 3. scripts/push_monitor.py(推送监控脚本)

  • [x] 调用auto_push_system.py
  • [x] 检查执行结果
  • [x] 处理异常情况
  • [x] 记录日志
  • [x] 发送告警(如果需要)
  • [x] 系统健康检查
  • [x] 连续失败计数
  • [x] 可独立运行

设计原则验证

职责分离

  • [x] 代码负责:数据加载、选股、风控、报告生成、推送发送
  • [x] Agent负责:执行监控、异常判断、严重告警、用户通知

功能验证

独立运行性

  • [x] is_trading_day.py 可以独立运行
  • [x] auto_push_system.py 可以独立运行
  • [x] push_monitor.py 可以独立运行

返回值

  • [x] auto_push_system.run() 返回 (success, message)
  • [x] push_monitor.check_and_push() 返回结果状态

日志记录

  • [x] 所有操作都有日志记录
  • [x] 日志包含时间戳、步骤、状态

异常处理

  • [x] 每个关键步骤都有try-catch
  • [x] 失败有明确的错误信息
  • [x] 系统级异常不会崩溃

文件权限

  • [x] 三个脚本都有可执行权限(chmod +x)

语法检查

  • [x] 所有脚本通过 py_compile 检查
  • [x] 模块导入验证通过

使用说明

直接运行各脚本

# 判断交易日
python3 scripts/is_trading_day.py

# 执行完整推送流程(代码负责)
python3 scripts/auto_push_system.py

# 执行推送监控(Agent负责)
python3 scripts/push_monitor.py

Cron配置

根据 docs/PUSH_WORKFLOW_OPTIMIZATION.md,建议配置:

# 工作日8:00 - 自动推送(代码负责,Agent监控)
0 8 * * 1-5 cd /Users/variya/.openclaw/workspace/projects/a-stock-advisor && /opt/homebrew/bin/python3 scripts/auto_push_system.py >> logs/auto_push.log 2>&1

# 工作日8:05 - 推送监控(Agent负责)
5 8 * * 1-5 cd /Users/variya/.openclaw/workspace/projects/a-stock-advisor && /opt/homebrew/bin/python3 scripts/push_monitor.py >> logs/push_monitor.log 2>&1

# 工作日18:30 - 日报推送
30 18 * * 1-5 cd /Users/variya/.openclaw/workspace/projects/a-stock-advisor && /opt/homebrew/bin/python3 scripts/auto_push_system.py >> logs/auto_push.log 2>&1

架构说明

调用关系

Cron Schedule
    |
    → push_monitor.py (Agent层)
        |   → is_trading_day.py (判断交易日)
        |   → check_push_system_health() (健康检查)
        |
        → auto_push_system.py (代码层)
            |   → AlphaStockSelector (选股)
            |   → PortfolioTracker (持仓)
            |   → RebalanceStrategy (换仓)
            |   → RiskControlSystem (风控)
            |   → FeishuPusher (推送)
            |
            → 返回 (success, message)
        |
        → 判断结果,处理异常
        → 生成告警(如果需要)

错误处理层次

  1. 代码层(auto_push_system.py):
  • 捕获业务逻辑错误
  • 记录详细日志
  • 尝试恢复(使用备用数据等)
  • 返回失败状态给监控层
  1. 监控层(push_monitor.py):
  • 监控执行状态
  • 统计连续失败次数
  • 判断是否需要重试
  • 发送严重告警
  1. Agent层(人工介入):
  • 接收严重告警
  • 分析日志
  • 决定是否需要人工干预

下一步建议

  1. 测试完整流程
  2. 验证飞书推送
  3. 配置Cron任务
  4. 监控日志输出
  5. 根据实际运行情况进行优化

验证日期: 2026-03-02
状态: ✓ 所有验证通过