#scheduler #tasks #task-scheduler #task #time

white_rabbit

Task scheduler, allowing timed execution, repeated or not

2 releases

0.1.1 May 9, 2019
0.1.0 May 9, 2019

#23 in #task-scheduler

Download history 1/week @ 2023-12-11 7/week @ 2023-12-18 5/week @ 2024-01-08 8/week @ 2024-02-12 18/week @ 2024-02-19 42/week @ 2024-02-26 23/week @ 2024-03-04 34/week @ 2024-03-11 22/week @ 2024-03-18

122 downloads per month
Used in danmuji

ISC license

16KB
240 lines

ci-badge docs-badge rust badge crates.io version

“I'm late! I'm late! For a very important date!”

by “The White Rabbit” 『Alice's Adventures in Wonderland』

About

white_rabbit schedules your tasks and can repeat them!

One funny use case are chat bots, e.g. a remind me-command that might be repeated after a user-specified time.

We are using chrono's DateTime<Utc>, enabling you to serialise and thus backup currently running tasks, in case you want to shutdown/restart your application, constructing a new scheduler is doable. However, please make sure your internal clock is synced.

Everyone is welcome to contribute, check out the CONTRIBUTING.md for further guidance.

Example

Let's have a look at a code-example:

use white_rabbit::{DateResult, Duration, Scheduler};

fn main() {
    let mut scheduler = Scheduler::new(4);

    scheduler.add_task_duration(Duration::seconds(5), |_| {
        println!("I'm here!");

        DateResult::Done
    });
}

Precision

The scheduler sleeps when unneeded. Due to preemption or different implementations across operating systems, it may occur that the scheduler will sleep longer than intended.

Be aware, an incorrect system clock may lead to tasks being run earlier or later.

Installation

Add this to your Cargo.toml:

[dependencies]
white_rabbit = "0.1.0"

Dependencies

~2.8–5.5MB
~86K SLoC