Fluent Schedule
A human-readable, fluent task scheduling library for Rust. This library provides a simple API for scheduling tasks without using complex cron syntax.
Features
- Fluent API: Chain methods to build schedules in a readable way
- Flexible Scheduling: Support for intervals, specific times, and day-of-week scheduling
- Type Safety: Compile-time guarantees for valid configurations
- Error Handling: Clear error messages for invalid configurations
- Zero Dependencies: Only depends on
chronofor time handling - Thread Safe: Jobs can be safely shared across threads
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Basic Interval Scheduling
use ;
Time-Based Scheduling
use ;
use Weekday;
Multiple Jobs
use ;
use Weekday;
API Overview
Job Builder Methods
Job::new()- Create a new job.every(duration)- Run at fixed intervals.at(time_str)- Run at specific time (HH:MM or HH:MM:SS).on(weekday)- Run on specific days of the week.on_weekday()- Run Monday through Friday.on_weekend()- Run Saturday and Sunday.run(closure)- Set the task to execute
Fluent Duration Extensions
The library extends unsigned integers with time unit methods:
use FluentDuration;
let five_seconds = 5u32.seconds;
let ten_minutes = 10u32.minutes;
let two_hours = 2u32.hours;
Scheduler Methods
Scheduler::new()- Create a new scheduler.add(job)- Add a configured job (returns Result).run_forever()- Start the scheduler (blocks current thread)
Error Handling
The library uses SchedulerError for configuration issues:
use ;
let invalid_job = new.at.run;
let mut scheduler = new;
match scheduler.add
Examples
See the examples/ directory for more usage examples:
simple.rs- Basic usage with multiple job types
Run an example:
Testing
Run the test suite:
Run with verbose output:
Documentation
Generate and view documentation:
Performance Considerations
- The scheduler runs in a single thread and blocks on
run_forever() - Jobs should be lightweight to avoid blocking other scheduled tasks
- For CPU-intensive tasks, consider spawning threads within the job closure
- The scheduler calculates sleep durations dynamically based on the next job's schedule
Limitations
- Single-threaded execution (jobs run sequentially)
- No persistence (schedules are lost on restart)
- Time precision is limited to seconds
- No support for complex cron-like expressions
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for version history and changes.