← Back to library

从“只会 heartbeat 吗?”到可控自治:heartbeat + cron 分层执行手册

问题/场景:用户常把 OpenClaw 的自动化误解为“只能 heartbeat 轮询”。前置:可编辑 HEARTBEAT.md、可创建 cron。实施步骤:用 heartbeat 做批处理巡检,用 cron 做准点触发和一次性提醒,再加状态文件去重。关键命令:`openclaw cron list`、`openclaw cron add`。验证:同类任务不重复提醒、准点任务按时触发。风险:把所有任务都塞到 heartbeat 会造成噪音与漂移。来源:Reddit 讨论 + 官方 cron 文档交叉整理。

REDDITDiscovered 2026-02-21Author hotweights
Prerequisites
  • Heartbeat is enabled and you can edit `HEARTBEAT.md` in the workspace.
  • You have permission to create/update cron jobs for precise schedules.
Steps
  1. Classify tasks into two buckets: (a) periodic checks tolerant to drift, (b) exact-time triggers.
  2. Put A-class tasks in `HEARTBEAT.md` as a compact checklist and run them in one batched pass.
  3. Create cron jobs for B-class tasks (meeting reminders, one-shot follow-ups, fixed-time sends).
  4. Record last-run timestamps in a state file and skip when not due to prevent duplicate notifications.
  5. Review weekly: move noisy heartbeat items to cron or reduce frequency if they produce low-value alerts.
Commands
openclaw cron list
openclaw cron add
openclaw cron runs <jobId>
Verify

Heartbeat messages stay concise while exact-time reminders arrive on schedule without duplicates for at least 3 days.

Caveats
  • Cron payload/sessionTarget combinations are constrained by OpenClaw schema; invalid combinations will fail.
  • Exact cron CLI flags may vary by release; verify with local help/docs before applying in production(需验证).
Source attribution

This tip is aggregated from community/public sources and preserved with attribution.

Open original source ↗
Visit original post