# Uhrwerk, a simple scheduler  [](https://crates.io/crates/uhrwerk) [](https://docs.rs/uhrwerk) [](https://codeberg.org/proto-x/uhrwerk)
Uhrwerk is a simple scheduler,
forked from [clokwerk][__link0], which itself is inspired
by Python’s [Schedule][__link1]
and Ruby’s [clockwork][__link2].
It uses a similar DSL for scheduling, rather than parsing cron strings.
Uhrwerk supports both synchronous and asynchronous tasks.
## Usage
```rust
// 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`][__link3].
For more details, see [`Scheduler`][__link4] or its async counterpart, [`AsyncScheduler`][__link5].
## 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*.
[__cargo_doc2readme_dependencies_info]: ggGmYW0CYXZlMC43LjNhdIQb0SU-UrW4f_sblfC0AsXL7NUby_0I2mYqRSobjLEYaMrjEbVhYvRhcoQblqg02ksHYYgbWeiQd6pKPhsbEvtfxTbNLsobKj_N6B8KM4lhZIGCZ3VocndlcmtlMC4xLjA
[__link0]: https://crates.io/crates/clokwerk
[__link1]: https://schedule.readthedocs.io/en/stable/
[__link2]: https://github.com/Rykian/clockwork
[__link3]: https://docs.rs/uhrwerk/0.1.0/uhrwerk/?search=scheduler::Scheduler::new_with_utc_offset
[__link4]: https://docs.rs/uhrwerk/0.1.0/uhrwerk/?search=scheduler::Scheduler
[__link5]: https://docs.rs/uhrwerk/0.1.0/uhrwerk/?search=async_scheduler::AsyncScheduler