CronTab
A lightweight, thread-safe cron job scheduler for Rust with support for both sync and async execution.
Features
- ⚡ Sync & Async - Choose the execution mode that fits your application
- 🌍 Timezone Aware - Full timezone support via chrono
- 🎯 Second Precision - 7-field cron expressions with second-level scheduling
- 🔧 Runtime Control - Add, remove, start, and stop jobs dynamically
- 🛡️ Thread Safe - Built with Rust's safety guarantees
Installation
Add to your Cargo.toml:
[]
= { = "0.2", = ["sync", "async"] }
Usage
Synchronous Jobs
use Utc;
use Cron;
Asynchronous Jobs
use Utc;
use AsyncCron;
async
Cron Expression Format
CronTab uses 7-field cron expressions with second precision:
sec min hour day month weekday year
* * * * * * *
Field ranges:
sec: 0-59min: 0-59hour: 0-23day: 1-31month: 1-12weekday: 0-6 (Sunday=0)year: 1970-3000
Common patterns:
| Expression | Description |
|---|---|
* * * * * * * |
Every second |
0 * * * * * * |
Every minute |
0 0 * * * * * |
Every hour |
0 0 0 * * * * |
Daily at midnight |
0 0 9 * * MON-FRI * |
Weekdays at 9 AM |
0 30 14 * * * * |
Daily at 2:30 PM |
Advanced Examples
Managing Jobs Dynamically
use Utc;
use Cron;
Shared State in Async Jobs
use Arc;
use Utc;
use AsyncCron;
use Mutex;
async
Using Custom Timezones
use FixedOffset;
use Cron;
Feature Flags
Choose the features you need:
# Sync only (default)
= "0.2"
# Async only
= { = "0.2", = ["async"] }
# Both sync and async
= { = "0.2", = ["all"] }
Examples
Run the included examples:
# Synchronous example
# Asynchronous example
Testing
# All tests
# Sync tests only
# Async tests only
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run
cargo fmtandcargo clippy --all-features - Submit a pull request
For major changes, open an issue first to discuss your proposal.
License
MIT License - see LICENSE for details.
Links
- Documentation - Full API reference
- Crates.io - Package registry
- Repository - Source code