a3s-cron
Cron scheduling library for A3S with natural language support.
Features
- Standard Cron Syntax: 5-field cron expressions (minute hour day month weekday)
- Natural Language: Parse schedules from English and Chinese
- Persistence: JSON file-based storage with pluggable backends
- CRUD Operations: Create, pause, resume, update, and remove jobs
- Execution History: Track job runs with output and status
- 71 Unit Tests: Comprehensive test coverage
Installation
[]
= "0.1"
Library Usage
use ;
async
CLI Usage (via a3s-tools)
# Parse natural language to cron expression
TOOL_ARGS='{"action":"parse","input":"every day at 2am"}'
# Output: Cron expression: 0 2 * * *
TOOL_ARGS='{"action":"parse","input":"每周一上午9点"}'
# Output: Cron expression: 0 9 * * 1
# Create a job with natural language schedule
TOOL_ARGS='{"action":"add","name":"backup","schedule":"every day at 3am","command":"./backup.sh"}'
# List all jobs
TOOL_ARGS='{"action":"list"}'
# Get job details
TOOL_ARGS='{"action":"get","id":"<job-id>"}'
# Manually run a job
TOOL_ARGS='{"action":"run","id":"<job-id>"}'
# View execution history
TOOL_ARGS='{"action":"history","id":"<job-id>"}'
# Pause a job
TOOL_ARGS='{"action":"pause","id":"<job-id>"}'
# Resume a job
TOOL_ARGS='{"action":"resume","id":"<job-id>"}'
# Update job schedule
TOOL_ARGS='{"action":"update","id":"<job-id>","schedule":"every monday at 9am"}'
# Remove a job
TOOL_ARGS='{"action":"remove","id":"<job-id>"}'
Natural Language Support
English
| Expression | Cron | Description |
|---|---|---|
every minute |
* * * * * |
Every minute |
every 5 minutes |
*/5 * * * * |
Every 5 minutes |
every hour |
0 * * * * |
Every hour |
every 2 hours |
0 */2 * * * |
Every 2 hours |
daily at 2am |
0 2 * * * |
Daily at 2:00 AM |
every day at 14:30 |
30 14 * * * |
Daily at 2:30 PM |
weekly on monday at 9am |
0 9 * * 1 |
Every Monday at 9:00 AM |
monthly on the 15th |
0 0 15 * * |
15th of every month |
every weekday at 8am |
0 8 * * 1-5 |
Mon-Fri at 8:00 AM |
every weekend at 10am |
0 10 * * 0,6 |
Sat-Sun at 10:00 AM |
Chinese (中文)
| 表达式 | Cron | 描述 |
|---|---|---|
每分钟 |
* * * * * |
每分钟执行 |
每5分钟 |
*/5 * * * * |
每5分钟执行 |
每小时 |
0 * * * * |
每小时执行 |
每2小时 |
0 */2 * * * |
每2小时执行 |
每天凌晨2点 |
0 2 * * * |
每天凌晨2点 |
每天下午3点30分 |
30 15 * * * |
每天下午3:30 |
每周一上午9点 |
0 9 * * 1 |
每周一上午9点 |
每月15号 |
0 0 15 * * |
每月15号 |
工作日上午9点 |
0 9 * * 1-5 |
工作日上午9点 |
周末上午10点 |
0 10 * * 0,6 |
周末上午10点 |
Cron Expression Format
Standard 5-field cron format:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sun=0)
│ │ │ │ │
* * * * *
Special characters:
*- any value,- value list (e.g.,1,3,5)-- range (e.g.,1-5)/- step (e.g.,*/5)
Architecture
a3s-cron/
├── src/
│ ├── lib.rs # Public API
│ ├── types.rs # CronJob, JobStatus, JobExecution
│ ├── parser.rs # Cron expression parser
│ ├── natural.rs # Natural language parser
│ ├── store.rs # CronStore trait, FileCronStore, MemoryCronStore
│ └── scheduler.rs # CronManager with CRUD operations
└── Cargo.toml
License
MIT