网淘吧来吧,欢迎您!

Cron Retry技能使用说明

2026-03-28 新闻来源:网淘吧 围观:19
电脑广告
手机广告

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.

完成。每次心跳时,失败的网络任务会自动重试。

工作原理

  1. 心跳触发时,通过cron list
  2. 命令检查所有定时任务筛选出状态为lastStatus = "error"
  3. enabled = true的任务检查其
  4. lastError是否匹配网络相关错误模式
  5. 通过

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"

示例场景

  1. 晚上7:00— 晚间简报定时任务触发
  2. 网络中断— Telegram发送失败
  3. 任务标记为 lastStatus: "error",lastError: "发送'message'的网络请求失败!"
  4. 晚上7:15— 连接恢复,心跳检测运行
  5. 技能检测到失败的任务,识别为网络错误
  6. 重试该任务 → 简报发送成功
  7. 报告: "已恢复1个任务:晚间总结简报"

安全性

  • 仅重试临时网络错误
  • 尊重任务启用状态
  • 不会创建重试循环(检查lastRunAtMs)
  • 报告所有恢复尝试
免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326317名访客 今日有221篇新文章/评论