| name | cronjob-scheduling-patterns |
| description | Common patterns and pitfalls for scheduling cron jobs with the cronjob tool. Covers specific-time scheduling, recurrence patterns, and workarounds for cron expression limitations. |
Cronjob Scheduling Patterns
⚠️ Key Limitations
-
Standard cron expressions (e.g., 0 9 * * *) require croniter package
- If you get error: "Cron expressions require 'croniter' package"
- The environment may not have it installed
- Use workarounds below instead
-
Duration format "24h" schedules from NOW, not from midnight
schedule: "24h" → runs every 24 hours from current time
- NOT the same as "every day at 9am"
✅ Working Patterns
Pattern 1: Specific Time of Day (Daily at 9:00 AM)
Problem: Want daily execution at specific time (e.g., 09:00 Beijing time)
Solution: Use ISO timestamp for first run + repeat count
date -v+1d -v09H -v00M -v00S -Iseconds
cronjob create \
--name "Daily Morning Task" \
--schedule "2026-04-08T09:00:00+08:00" \
--repeat 9999 \
...
Result: First run at specified time, then repeats every 24h automatically
Pattern 2: Simple Recurring Duration
cronjob create --schedule "30m" --repeat 9999 ...
cronjob create --schedule "2h" --repeat 9999 ...
cronjob create --schedule "24h" --repeat 9999 ...
Pattern 3: One-time Scheduled Task
cronjob create \
--schedule "2026-04-08T15:30:00+08:00" \
--repeat 1 ...
🔧 Troubleshooting
| Error | Cause | Solution |
|---|
| "Cron expressions require 'croniter' package'" | Using 0 9 * * * format without croniter | Use ISO timestamp or duration format |
| "Invalid duration: 'day at 09:00'" | Unsupported natural language | Use duration (e.g., "24h") or timestamp |
| Job runs at wrong time | "24h" schedules from creation time | Use specific ISO timestamp for time-of-day |
📝 Best Practices
- Always use
--repeat with duration schedules (default is 1)
- For daily tasks at specific time: Calculate next occurrence timestamp explicitly
- Timezone: Include offset in ISO timestamp (e.g.,
+08:00 for Beijing)
- Verify next_run_at after creating job to confirm timing is correct
Example: Complete Daily News Briefing Setup
date -v+1d -v09H -v00M -v00S -Iseconds
cronjob create \
--name "每日全球新闻简报" \
--schedule "2026-04-08T09:00:00+08:00" \
--skill news-aggregator-skill \
--prompt "..." \
--deliver telegram \
--repeat 9999
cronjob list