11 releases

0.1.4 Aug 22, 2023
0.1.3 May 30, 2022
0.1.2 Sep 12, 2021
0.0.6 Sep 7, 2021
0.0.2 Aug 31, 2021

#67 in Date and time

Download history 44/week @ 2024-02-23 15/week @ 2024-03-01 8/week @ 2024-03-08 30/week @ 2024-03-15 82/week @ 2024-03-29

120 downloads per month

BSD-3-Clause

82KB
2K SLoC

skedge

Crates.io rust action docs.rs

Rust single-process scheduling. Ported from schedule for Python, in turn inspired by clockwork (Ruby), and "Rethinking Cron" by Adam Wiggins.

Usage

Documentation can be found on docs.rs.

This library uses the Builder pattern to define jobs. Instantiate a fresh Scheduler, then use the every() and every_single() functions to begin defining a job. Finalize configuration by calling Job::run() to add the new job to the scheduler. The Scheduler::run_pending() method is used to fire any jobs that have arrived at their next scheduled run time. Currently, precision can only be specified to the second, no smaller.

use chrono::Local;
use skedge::{every, Scheduler};
use std::thread::sleep;
use std::time::Duration;

fn greet(name: &str) {
    let now = Local::now().to_rfc2822();
    println!("Hello {name}, it's {now}!");
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut schedule = Scheduler::new();

    every(2)
        .to(8)?
        .seconds()?
        .until(Local::now() + chrono::Duration::seconds(30))?
        .run_one_arg(&mut schedule, greet, "Good-Looking")?;

    let now = Local::now();
    println!("Starting at {now}");
    loop {
        if let Err(e) = schedule.run_pending() {
            eprintln!("Error: {e}");
        }
        sleep(Duration::from_secs(1));
    }
}

Check out the example script to see more configuration options. Try cargo run --example readme or cargo run --example basic to see it in action.

CFFI

There is an experimental C foreign function interface, which is feature-gated and not included by default. To build the library with this feature, use cargo build --features ffi. See the Makefile and examples/ffi/c directory for details on using this library from C. Execute make run to build and execute the included example C program. It currently only supports work functions which take no arguments.

Development

Clone this repo. See CONTRIBUTING.md for contribution guidelines.

Dependencies

  • Stable Rust: The default stable toolchain is fine. Obtainable via rustup using the instructions at this link.

Crates

Development-Only

Dependencies

~5–7MB
~121K SLoC