#scheduler #job-scheduler #job #task-scheduler #job-scheduling

clokwerk

A simple Rust recurring task scheduler, similar to Python's schedule

10 releases

0.4.0 Nov 23, 2022
0.4.0-rc1 May 5, 2021
0.3.5 May 5, 2021
0.3.4 Dec 11, 2020
0.1.0 Sep 7, 2018

#119 in Date and time

Download history 2565/week @ 2023-12-11 2407/week @ 2023-12-18 1589/week @ 2023-12-25 2129/week @ 2024-01-01 2566/week @ 2024-01-08 2542/week @ 2024-01-15 2538/week @ 2024-01-22 2407/week @ 2024-01-29 2363/week @ 2024-02-05 2675/week @ 2024-02-12 2798/week @ 2024-02-19 2781/week @ 2024-02-26 3033/week @ 2024-03-04 2954/week @ 2024-03-11 3335/week @ 2024-03-18 2859/week @ 2024-03-25

12,330 downloads per month
Used in 19 crates (15 directly)

Apache-2.0

77KB
1.5K SLoC

Clokwerk, a simple scheduler

Crate API

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.

Since version 0.4, Clokwerk has also supported a separate AsyncScheduler, which can easily run asynchronous tasks concurrently.

Usage

// Scheduler, and trait for .seconds(), .minutes(), etc.
use clokwerk::{Scheduler, TimeUnits};
// Import week days and WeekDay
use clokwerk::Interval::*;
use std::thread;
use std::time::Duration;

// Create a new scheduler
let mut scheduler = Scheduler::new();
// or a scheduler with a given timezone
let mut scheduler = Scheduler::with_tz(chrono::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();

See documentation for additional examples of usage.

Similar libraries

Dependencies

~1–8MB
~27K SLoC