Cron Retry技能使用说明
2026-03-28
新闻来源:网淘吧
围观:23
电脑广告
手机广告
Cron 重试技能
自动检测并重试因网络/连接错误而失败的定时任务。
快速开始(集成心跳机制)
将此添加到你的HEARTBEAT.md文件中:
## Cron Recovery Check
Check for cron jobs with lastStatus: "error". If the error matches network patterns (connection error, sendMessage failed, fetch failed, ETIMEDOUT, ECONNREFUSED), retry the job using cron tool with action: "run" and the job ID. Report what was recovered.
完成。每次心跳时,失败的网络任务会自动重试。
工作原理
- 心跳触发时,通过
cron list - 命令检查所有定时任务
筛选出状态为lastStatus = "error"且 - enabled = true
的任务检查其 - lastError
是否匹配网络相关错误模式 - 通过
cron run
命令重新运行符合条件的任务
网络请求失败连接错误连接被拒绝连接超时域名查找失败发送消息失败获取失败套接字挂起
重试与跳过规则
重试情况:
- 网络超时
- 连接被拒绝
- 消息发送失败
- DNS查找失败
跳过(不重试)情况:
- 逻辑错误(配置错误、数据缺失)
- 认证失败
- 已禁用的任务
- 刚刚成功执行的任务
手动恢复检查
手动检查和重试失败任务:
# List all jobs and their status
clawdbot cron list
# Find failed jobs
clawdbot cron list | jq '.jobs[] | select(.state.lastStatus == "error") | {name, error: .state.lastError}'
# Retry a specific job
clawdbot cron run --id <JOB_ID>
代理实现
实现心跳检查时:
1. Call cron tool with action: "list"
2. For each job in response.jobs:
- Skip if job.enabled !== true
- Skip if job.state.lastStatus !== "error"
- Check if job.state.lastError matches network patterns
- If retryable: call cron tool with action: "run", jobId: job.id
3. Report: "Recovered X jobs" or "No failed jobs to recover"
示例场景
- 晚上7:00— 晚间简报定时任务触发
- 网络中断— Telegram发送失败
- 任务标记为
lastStatus: "error",lastError: "发送'message'的网络请求失败!" - 晚上7:15— 连接恢复,心跳检测运行
- 技能检测到失败的任务,识别为网络错误
- 重试该任务 → 简报发送成功
- 报告: "已恢复1个任务:晚间总结简报"
安全性
- 仅重试临时网络错误
- 尊重任务启用状态
- 不会创建重试循环(检查lastRunAtMs)
- 报告所有恢复尝试
文章底部电脑广告
手机广告位-内容正文底部


微信扫一扫,打赏作者吧~