Overview
The cron service supports:- One-time tasks (reminders)
- Recurring intervals (every N seconds)
- Cron expressions (traditional cron syntax)
- Shell command execution
- Agent message processing
- Multi-channel delivery
Schedule Types
One-Time (at)
Execute once at a specific time:- Executes once at specified timestamp
- Automatically disabled after execution
- Deleted if
DeleteAfterRun: true
Recurring Interval (every)
Repeat at fixed intervals:- Repeats at fixed interval
- Next run computed after each execution
- Continues until disabled
Cron Expression (cron)
Use traditional cron syntax:0 9 * * *- Daily at 9:00 AM*/15 * * * *- Every 15 minutes0 0 * * 0- Weekly on Sunday at midnight0 0 1 * *- Monthly on the 1st at midnight
Job Structure
CronJob
CronPayload
CronJobState
Using the Cron Service
Creating the Service
Adding Jobs
One-time Reminder:Managing Jobs
List Jobs:Service Control
Start:Using the Cron Tool
Agents can manage cron jobs through thecron tool:
Add Reminder
Schedule Recurring Task
Execute Shell Command
List Jobs
Remove Job
Execution Modes
Direct Delivery (deliver: true)
Message is sent directly to the channel without agent processing:- Simple reminders
- Notifications
- Alerts
- Message sent via message bus
- No LLM processing
- Fast execution
Agent Processing (deliver: false)
Message is processed by the agent, which can use tools:- Complex tasks requiring tools
- Dynamic responses
- Multi-step workflows
- Message sent to agent loop
- Agent can call tools
- Response generated by LLM
Command Execution
Direct shell command execution:- System maintenance
- Automated builds
- Monitoring scripts
- Command executed via exec tool
- Output sent to channel
- Errors reported
Storage
Jobs are persisted to JSON:<workspace>/.weaver/cron.json
Auto-save: Jobs are saved after every modification.
Scheduler Implementation
Tick Loop
The scheduler runs a 1-second tick loop:Execution Flow
- Check all enabled jobs
- Find jobs where
NextRunAtMS <= now - Reset
NextRunAtMSto prevent duplicate execution - Execute jobs outside lock (parallel)
- Update job state after completion
- Compute next run time
- Save state to disk
Next Run Computation
At (one-time):- If
AtMS > now: returnAtMS - If
AtMS <= now: returnnil(disable job)
NextRunAtMS = now + EveryMS
- Parse expression with
gronx - Compute next occurrence after current time
- Return timestamp
Error Handling
Errors during job execution are logged but don’t stop the scheduler:job.State.LastStatus and LastError.
Best Practices
-
Use appropriate schedule type:
atfor one-time reminderseveryfor simple recurring taskscronfor complex schedules
-
Set meaningful names:
- Helps identify jobs in listings
- Truncated to 30 chars for display
-
Choose delivery mode wisely:
deliver: truefor simple notificationsdeliver: falsefor tasks requiring agent intelligence
-
Handle errors gracefully:
- Check
LastStatusandLastError - Implement retry logic if needed
- Check
-
Clean up completed jobs:
- Use
DeleteAfterRunfor one-time tasks - Manually remove old jobs
- Use
-
Validate cron expressions:
- Test expressions before deployment
- Use online validators
-
Consider timezone:
- All timestamps are Unix milliseconds (UTC)
- Convert to local time for display
Performance
- 1-second precision: Jobs execute within 1 second of scheduled time
- Parallel execution: Multiple due jobs run concurrently
- Lock-free reads: Listing jobs doesn’t block execution
- Efficient storage: JSON files are compact and fast
Security
- Command execution: Uses exec tool with safety guards
- File permissions: Storage file is 0600 (user-only)
- Channel validation: Jobs can only target configured channels
- No code injection: Job payloads are data, not code