Cron Retry Skill
Automatically detect and retry cron jobs that failed due to network/connection errors.
Quick Start (Heartbeat Integration)
Add this to your HEARTBEAT.md:
CODEBLOCK0
That's it. On each heartbeat, failed network jobs get retried automatically.
How It Works
- 1. On heartbeat, check all cron jobs via INLINECODE1
- Filter for jobs where
lastStatus = "error" and INLINECODE3 - Check if
lastError matches network-related patterns - Re-run eligible jobs via INLINECODE5
- Report results
Network Error Patterns (Retryable)
These errors indicate transient network issues worth retrying:
- - INLINECODE6
- INLINECODE7
- INLINECODE8
- INLINECODE9
- INLINECODE10
- INLINECODE11
- INLINECODE12
- INLINECODE13
What Gets Retried vs Skipped
Retried:
- - Network timeouts
- Connection refused
- Message send failures
- DNS lookup failures
Skipped (not retried):
- - Logic errors (bad config, missing data)
- Auth failures
- Disabled jobs
- Jobs that just ran successfully
Manual Recovery Check
To check and retry failed jobs manually:
CODEBLOCK1
Agent Implementation
When implementing the heartbeat check:
CODEBLOCK2
Example Scenario
- 1. 7:00 PM — Evening briefing cron fires
- Network hiccup — Telegram send fails
- Job marked
lastStatus: "error", INLINECODE15 - 7:15 PM — Connection restored, heartbeat runs
- Skill detects the failed job, sees it's a network error
- Retries the job → briefing delivered
- Reports: "Recovered 1 job: evening-wrap-briefing"
Safety
- - Only retries transient network errors
- Respects job enabled state
- Won't create retry loops (checks lastRunAtMs)
- Reports all recovery attempts
Cron 重试技能
自动检测并重试因网络/连接错误而失败的定时任务。
快速开始(心跳集成)
将以下内容添加到你的 HEARTBEAT.md 中:
markdown
定时任务恢复检查
检查 lastStatus 为 error 的定时任务。如果错误匹配网络模式(connection error、sendMessage failed、fetch failed、ETIMEDOUT、ECONNREFUSED),使用 cron 工具以 action: run 和任务 ID 重试该任务。报告已恢复的内容。
就这样。每次心跳时,失败的网络任务会自动重试。
工作原理
- 1. 心跳时,通过 cron list 检查所有定时任务
- 筛选出 lastStatus = error 且 enabled = true 的任务
- 检查 lastError 是否匹配网络相关模式
- 通过 cron run 重新运行符合条件的任务
- 报告结果
网络错误模式(可重试)
这些错误表示值得重试的临时网络问题:
- - Network request.failed
- Connection error
- ECONNREFUSED
- ETIMEDOUT
- ENOTFOUND
- sendMessage.failed
- fetch failed
- socket hang up
重试与跳过的内容
重试:
- - 网络超时
- 连接被拒绝
- 消息发送失败
- DNS 查找失败
跳过(不重试):
- - 逻辑错误(配置错误、数据缺失)
- 认证失败
- 已禁用的任务
- 刚刚成功运行的任务
手动恢复检查
要手动检查和重试失败的任务:
bash
列出所有任务及其状态
clawdbot cron list
查找失败的任务
clawdbot cron list | jq .jobs[] | select(.state.lastStatus == error) | {name, error: .state.lastError}
重试特定任务
clawdbot cron run --id
代理实现
实现心跳检查时:
- 1. 调用 cron 工具,action: list
- 对于 response.jobs 中的每个任务:
- 如果 job.enabled !== true 则跳过
- 如果 job.state.lastStatus !== error 则跳过
- 检查 job.state.lastError 是否匹配网络模式
- 如果可重试:调用 cron 工具,action: run,jobId: job.id
- 3. 报告:已恢复 X 个任务 或 没有需要恢复的失败任务
示例场景
- 1. 晚上 7:00 — 晚间简报定时任务触发
- 网络故障 — Telegram 发送失败
- 任务标记 lastStatus: error,lastError: Network request for sendMessage failed!
- 晚上 7:15 — 连接恢复,心跳运行
- 技能检测到失败的任务,发现是网络错误
- 重试该任务 → 简报成功发送
- 报告:已恢复 1 个任务:evening-wrap-briefing
安全性
- - 仅重试临时网络错误
- 尊重任务启用状态
- 不会创建重试循环(检查 lastRunAtMs)
- 报告所有恢复尝试