Clokwerk, a simple scheduler
Clokwerk is a simple scheduler, inspired by Python's Schedule and Ruby's clockwork. It uses a similar DSL for scheduling, rather than parsing cron strings.
By default, times and dates are relative to the local timezone, but the scheduler can be made to use a
different timezone using the Scheduler::with_tz
constructor.
Usage
// Scheduler, and trait for .seconds(), .minutes(), etc.
use ;
// Import week days and WeekDay
use *;
use thread;
use Duration;
// Create a new scheduler
let mut scheduler = new;
// or a scheduler with a given timezone
let mut scheduler = with_tz;
// Add some tasks to it
scheduler.every.plus.run;
scheduler.every.at.run;
scheduler.every.at.run;
scheduler.every.run;
// Manually run the scheduler in an event loop
for _ in 1..10
// Or run it in a background thread
let thread_handle = scheduler.watch_thread;
// The scheduler stops when `thread_handle` is dropped, or `stop` is called
thread_handle.stop;
Caveats
Some combinations of times or intervals are permissible, but make little sense, e.g. every(10.seconds()).at("16:00")
, which would next run at the next 4 PM after the next multiple of 10 seconds.
Similar libraries
- schedule-rs and job_scheduler are two other Rust scheduler libraries. Both use
cron
syntax for scheduling.