AgentSkillsCN

cron-mastery

熟练掌握 Cron 定时调度,轻松实现自动化任务、提醒事项以及周期性工作流。

SKILL.md
--- frontmatter
name: cron-mastery
version: 1.0.0
description: Master cron scheduling for automated tasks, reminders, and periodic workflows.
metadata:
  openclaw:
    emoji: ⏰
    category: automation

Cron Mastery

Schedule automated tasks, reminders, and periodic workflows using OpenClaw's cron system.

Quick Reference

Schedule Types

TypeFormatExample
atISO timestamp2026-02-20T09:00:00Z
everyInterval in mseveryMs: 3600000 (1 hour)
cronCron expression0 9 * * 1-5 (9am weekdays)

Common Patterns

yaml
# Daily at 9am
cron: "0 9 * * *"

# Every hour
everyMs: 3600000

# Monday at 8am
cron: "0 8 * * 1"

# Every 30 minutes during business hours
cron: "*/30 9-17 * * 1-5"

Use Cases

1. Daily Morning Brief

json
{
  "name": "morning-brief",
  "schedule": {"kind": "cron", "expr": "0 8 * * *", "tz": "Europe/Berlin"},
  "payload": {"kind": "agentTurn", "message": "Generate morning brief: check emails, calendar, priorities"},
  "sessionTarget": "isolated"
}

2. Periodic Health Checks

json
{
  "name": "health-check",
  "schedule": {"kind": "every", "everyMs": 3600000},
  "payload": {"kind": "systemEvent", "text": "Heartbeat: check system status"},
  "sessionTarget": "main"
}

3. Reminder

json
{
  "name": "meeting-reminder",
  "schedule": {"kind": "at", "at": "2026-02-20T14:30:00Z"},
  "payload": {"kind": "systemEvent", "text": "Reminder: Meeting in 30 minutes"},
  "sessionTarget": "main"
}

Job Management

ActionCommand
List jobscron(action="list")
Add jobcron(action="add", job={...})
Updatecron(action="update", jobId="xxx", patch={...})
Removecron(action="remove", jobId="xxx")
Run nowcron(action="run", jobId="xxx")
Historycron(action="runs", jobId="xxx")

Best Practices

  1. Use isolated sessions for agentTurn jobs (clean context)
  2. Set notify=true for user-facing reminders
  3. Use descriptive names for easy identification
  4. Test before scheduling — use run(action="run") first
  5. Review runs periodically — check for failures

Heartbeat vs Cron

UseCronHeartbeat
Exact timing
Isolated execution
User reminders⚠️
Batch checks
Context-dependent

Example: Self-Improving Agent Schedule

json
{
  "name": "weekly-learning-review",
  "schedule": {"kind": "cron", "expr": "0 10 * * 0", "tz": "Europe/Berlin"},
  "payload": {
    "kind": "agentTurn",
    "message": "Review self-improving-agent learnings. Consolidate to MEMORY.md. Report insights."
  },
  "sessionTarget": "isolated",
  "notify": true
}