| Crates.io | fluent_schedule |
| lib.rs | fluent_schedule |
| version | 1.0.1 |
| created_at | 2025-11-08 20:04:09.698584+00 |
| updated_at | 2025-11-10 12:21:24.538692+00 |
| description | A human-readable, fluent task scheduling library for Rust. |
| homepage | |
| repository | https://github.com/Jacques-Murray/fluent_schedule |
| max_upload_size | |
| id | 1923235 |
| size | 56,096 |
A human-readable, fluent task scheduling library for Rust. This library provides a simple API for scheduling tasks without using complex cron syntax.
chrono for time handlingAdd this to your Cargo.toml:
[dependencies]
fluent_schedule = "1.0.0"
use fluent_schedule::{Job, Scheduler, FluentDuration};
fn main() {
// Create a job that runs every 5 seconds
let job = Job::new()
.every(5u32.seconds())
.run(|| println!("Task executed every 5 seconds!"));
// Create and start the scheduler
let mut scheduler = Scheduler::new();
scheduler.add(job).expect("Failed to add job");
// This blocks the current thread
scheduler.run_forever();
}
use fluent_schedule::{Job, Scheduler};
use chrono::Weekday;
fn main() {
// Create a job that runs at 5:00 PM on weekdays
let job = Job::new()
.on_weekday()
.at("17:00")
.run(|| println!("End of workday!"));
let mut scheduler = Scheduler::new();
scheduler.add(job).expect("Failed to add job");
scheduler.run_forever();
}
use fluent_schedule::{Job, Scheduler, FluentDuration};
use chrono::Weekday;
fn main() {
let job1 = Job::new()
.every(10u32.seconds())
.run(|| println!("Heartbeat every 10 seconds"));
let job2 = Job::new()
.on(Weekday::Mon)
.at("09:00")
.run(|| println!("Monday morning meeting"));
let job3 = Job::new()
.on_weekend()
.at("10:00")
.run(|| println!("Weekend task"));
let mut scheduler = Scheduler::new();
scheduler.add(job1).expect("Failed to add job1");
scheduler.add(job2).expect("Failed to add job2");
scheduler.add(job3).expect("Failed to add job3");
scheduler.run_forever();
}
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 executeThe library extends unsigned integers with time unit methods:
use fluent_schedule::FluentDuration;
let five_seconds = 5u32.seconds();
let ten_minutes = 10u32.minutes();
let two_hours = 2u32.hours();
Scheduler::new() - Create a new scheduler.add(job) - Add a configured job (returns Result).run_forever() - Start the scheduler (blocks current thread)The library uses SchedulerError for configuration issues:
use fluent_schedule::{Job, Scheduler, SchedulerError};
let invalid_job = Job::new().at("99:99").run(|| {});
let mut scheduler = Scheduler::new();
match scheduler.add(invalid_job) {
Ok(()) => println!("Job added successfully"),
Err(SchedulerError::InvalidTimeFormat(time)) => {
eprintln!("Invalid time format: {}", time);
}
Err(SchedulerError::TaskNotSet) => {
eprintln!("Job must have a task set with .run()");
}
}
See the examples/ directory for more usage examples:
simple.rs - Basic usage with multiple job typesRun an example:
cargo run --example simple
Run the test suite:
cargo test
Run with verbose output:
cargo test --verbose
Generate and view documentation:
cargo doc --open
run_forever()Contributions are welcome! Please see CONTRIBUTING.md for details.
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for version history and changes.