siafu-0.0.12 has been yanked.
Ergonomic Job Scheduler Library
A flexible and ergonomic job scheduling library for Rust applications with an intuitive, fluent public API.
Why "Siafu"?
The name "Siafu" refers to safari ants (also known as driver ants or army ants), which are famous for their highly organized and efficient colony operations. These fascinating insects:
- Work in perfect coordination with specialized roles for different tasks
- Execute complex operations through distributed intelligence
- Can adapt their scheduling and routing based on environmental changes
- Form living bridges and structures to overcome obstacles
Just like these remarkable ants, the Siafu library excels at organizing, scheduling, and executing tasks in a coordinated manner. The library embodies the efficiency, reliability, and adaptability of safari ants' work patterns, making it the perfect metaphor for a job scheduling system.
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: