CronTab
A modern, feature-rich cron job scheduler library for Rust applications with both synchronous and asynchronous execution support.
β¨ Features
- π Dual Execution Modes: Support for both synchronous and asynchronous job execution
- π Timezone Support: Full timezone handling with chrono integration
- β‘ High Performance: Efficient job scheduling with minimal overhead
- π‘οΈ Thread Safe: Built with Rust's safety guarantees in mind
- π― Flexible Scheduling: Standard cron expressions with second precision
- π§ Runtime Control: Add, remove, start, and stop jobs at runtime
- π¦ Zero Config: Works out of the box with sensible defaults
π Quick Start
Add CronTab to your Cargo.toml:
[]
= { = "0.2", = ["sync", "async"] }
Basic Synchronous Usage
use ;
use Cron;
Basic Asynchronous Usage
use ;
use AsyncCron;
async
π Cron Expression Format
CronTab supports 7-field cron expressions with second precision:
ββββββββββββββ second (0 - 59)
β ββββββββββββ minute (0 - 59)
β β ββββββββββ hour (0 - 23)
β β β ββββββββ day of month (1 - 31)
β β β β ββββββ month (1 - 12)
β β β β β ββββ day of week (0 - 6) (Sunday to Saturday)
β β β β β β ββ year (1970 - 3000)
β β β β β β β
* * * * * * *
Common Cron Patterns
| Expression | Description |
|---|---|
* * * * * * * |
Every second |
0 * * * * * * |
Every minute |
0 0 * * * * * |
Every hour |
0 0 0 * * * * |
Every day at midnight |
0 0 9 * * MON-FRI * |
Every weekday at 9 AM |
0 0 0 1 * * * |
First day of every month |
0 30 14 * * * * |
Every day at 2:30 PM |
π§ Advanced Usage
Managing Jobs at Runtime
use Utc;
use Cron;
Async Jobs with Shared State
use Arc;
use Utc;
use AsyncCron;
use Mutex;
async
Different Timezones
use ;
use Cron;
βοΈ Feature Flags
CronTab uses feature flags to minimize dependencies:
[]
# Include only sync support
= { = "0.2", = ["sync"] }
# Include only async support
= { = "0.2", = ["async"] }
# Include both (default)
= { = "0.2", = ["sync", "async"] }
# All features
= { = "0.2", = ["all"] }
π§ͺ Running Examples
# Run the synchronous example
# Run the asynchronous example
π API Documentation
For detailed API documentation, visit docs.rs/cron_tab.
π οΈ Development
Running Tests
# Run all tests
# Run only sync tests
# Run only async tests
Building Documentation
π€ Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Development Setup
- Clone the repository
- Install Rust (latest stable)
- Run tests:
cargo test --all-features - Check formatting:
cargo fmt - Run clippy:
cargo clippy --all-features
πLicense
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Built with cron for cron expression parsing
- Uses chrono for timezone handling
- Async support powered by tokio
Documentation β’ Crates.io β’ Repository