Ergonomic Job Scheduler Library
A flexible and ergonomic job scheduling library for Rust applications with an intuitive, fluent public API.
Features
- Schedule tasks to run on:
- Specific dates/times, e.g., 20 Sept 10:00 pm
- Recurring intervals, e.g., hourly, daily, weekly, monthly
- Random intervals, e.g., between 9-10 am
- Cron expressions for complex scheduling patterns
- Set limits on recurring jobs: hourly 5 times or daily x times, first Friday of every month
- Error handling and job monitoring capabilities
- Fluent builder API for easy job configuration
Usage Examples
Basic Usage
use ;
use ;
Scheduling Types
One-time jobs
// Run once at a specific time
let job = new
.once
.add_handler
.build;
Recurring jobs
// Run every 10 seconds
let job = new
.recurring
.repeat // Run up to 5 times
.add_handler
.build;
Cron jobs
use FromStr;
use Schedule;
// Run at specific times using cron expression
let cron_schedule = from_str?; // 9 AM on weekdays
let job = new
.cron
.add_handler
.build;
Random time jobs
// Run once at a random time within a range
let start = now + from_secs;
let end = now + from_secs;
let job = new
.random
.add_handler
.build;
Examples
Check out the examples directory for more comprehensive examples:
- basic_scheduler.rs: Demonstrates all scheduling types with simple examples
- real_world_scheduling.rs: Shows practical applications like database backups, newsletter sending, etc.
- advanced_scheduling.rs: Demonstrates job dependencies, error handling, and job monitoring
To run an example: