#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

#24 in #task-scheduler

Download history 22/week @ 2024-03-16 19/week @ 2024-03-23 69/week @ 2024-03-30 17/week @ 2024-04-06 21/week @ 2024-04-13 22/week @ 2024-04-20 17/week @ 2024-04-27 16/week @ 2024-05-04 21/week @ 2024-05-11 16/week @ 2024-05-18 21/week @ 2024-05-25 18/week @ 2024-06-01 7/week @ 2024-06-08 18/week @ 2024-06-15 22/week @ 2024-06-22 5/week @ 2024-06-29

54 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.7–5MB
~84K SLoC