OpenClaw从入门到应用——CLI:Cron
通过OpenClaw实现副业收入:《OpenClaw赚钱实录:从“养龙虾“到可持续变现的实践指南》
提示:运行
openclaw cron --help可查看完整命令界面。
注意:独立的cron add任务默认使用--announce方式交付。使用--no-deliver可将输出保留在内部。--deliver仍作为--announce的已弃用别名保留。
注意:一次性任务(--at)默认在成功执行后自动删除。使用--keep-after-run可保留它们。
注意:周期性任务在连续失败后会使用指数退避重试(30秒 → 1分钟 → 5分钟 → 15分钟 → 60分钟),并在下一次成功运行后恢复正常调度。
注意:openclaw cron run现在会在手动运行被加入执行队列后立即返回。成功响应包含{ ok: true, enqueued: true, runId };使用openclaw cron runs --id <runId>可跟踪最终执行结果。
注意:保留/修剪策略通过配置文件控制:
cron.sessionRetention(默认24h)会修剪已完成的独立运行会话。cron.runLog.maxBytes+cron.runLog.keepLines会修剪~/.openclaw/cron/runs/.jsonl。
升级提示:如果你有旧的定时任务(来自当前交付/存储格式之前的版本),请运行openclaw doctor --fix。该命令现在会规范化旧版 cron 字段(jobId、schedule.cron、顶层交付字段、payloadprovider交付别名),并在配置了cron.webhook时将简单的notify: truewebhook 回退任务迁移为显式 webhook 交付。
常用编辑操作
在不改变消息内容的情况下更新交付设置:
theme={"theme":{"light":"min-light","dark":"min-dark"}}openclawcronedit<jobId>--announce--channeltelegram--to"123456789"为独立任务禁用交付:
theme={"theme":{"light":"min-light","dark":"min-dark"}}openclawcronedit<jobId>--no-deliver为独立任务启用轻量级引导上下文:
theme={"theme":{"light":"min-light","dark":"min-dark"}}openclawcronedit<jobId>--light-context向特定频道发送通告:
theme={"theme":{"light":"min-light","dark":"min-dark"}}openclawcronedit<jobId>--announce--channelslack--to"channel:C1234567890"创建一个带有轻量级引导上下文的独立任务:
theme={"theme":{"light":"min-light","dark":"min-dark"}}openclawcronadd\--name"Lightweight morning brief"\--cron"0 7 * * *"\--sessionisolated\--message"Summarize overnight updates."\--light-context\--no-deliver--light-context仅适用于独立的 agent 轮次任务。对于 cron 运行,轻量级模式会使引导上下文保持为空,而不是注入完整的工作区引导集合。
