uhrwerk 0.1.0

Simple scheduler for recurring tasks
Documentation
  • Coverage
  • 69.39%
    34 out of 49 items documented9 out of 12 items with examples
  • Size
  • Source code size: 95.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.01 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • msrd0

Uhrwerk, a simple scheduler License: Apache-2.0 uhrwerk on crates.io uhrwerk on docs.rs Source Code Repository

Uhrwerk is a simple scheduler, forked from clokwerk, which itself is inspired by Python’s Schedule and Ruby’s clockwork. It uses a similar DSL for scheduling, rather than parsing cron strings.

Uhrwerk supports both synchronous and asynchronous tasks.

Usage

// Import week days and WeekDay
use uhrwerk::Interval::*;
// Scheduler and trait for .seconds(), .minutes(), etc.
use uhrwerk::{Job as _, Scheduler, TimeUnits as _};

// Create a new scheduler
let mut scheduler = Scheduler::new();
// or a scheduler with a given timezone
let mut scheduler = Scheduler::new_with_utc_offset(UtcOffset::UTC);
// Add some tasks to it
scheduler
	.every(10.minutes())
	.plus(30.seconds())
	.run(|| println!("Periodic task"));
scheduler
	.every(1.day())
	.at("3:20 pm")
	.run(|| println!("Daily task"));
scheduler
	.every(Tuesday)
	.at("14:20:17")
	.and_every(Thursday)
	.at("15:00")
	.run(|| println!("Biweekly task"));

// Manually run the scheduler in an event loop
for _ in 1 .. 10 {
	scheduler.run_pending();
	thread::sleep(Duration::from_millis(10));
}
// Or run it in a background thread
let thread_handle = scheduler.watch_thread(Duration::from_millis(100));
// The scheduler stops when `thread_handle` is dropped, or `stop` is called
thread_handle.stop();

By default, dates and times are relative to the local timezone, but the scheduler can be made to use a different timezone using Scheduler::new_with_utc_offset.

For more details, see Scheduler or its async counterpart, AsyncScheduler.

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.

Trivia

Uhrwerk is the German word for clockwork.