Rust single-process scheduling. Ported from schedule for Python

Overview

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.

Result<(), Box > { 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")?; println!("Starting at {}", Local::now()); loop { if let Err(e) = schedule.run_pending() { eprintln!("Error: {}", e); } sleep(Duration::from_secs(1)); } } ">
use chrono::Local;
use skedge::{every, Scheduler};
use std::thread::sleep;
use std::time::Duration;

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

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")?;

    println!("Starting at {}", Local::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

Issues
  • FFI?

    FFI?

    Maybe?

    enhancement 
    opened by deciduously 4
  • MVP functionality

    MVP functionality

    Tracking issue for basic working

    enhancement 
    opened by deciduously 2
  • Testing

    Testing

    Unit where possible, integration testing, Github CI passing.

    enhancement 
    opened by deciduously 2
  • MVP

    MVP

    This version should:

    • Execute all example code
    • Accept jobs taking no parameters, returning no data
    • Contain integration tests for all documented functionality
    opened by deciduously 1
  • More types of jobs

    More types of jobs

    Instead of just fn() -> (), we should be able to schedule many types of callable jobs.

    enhancement 
    opened by deciduously 1
  • Documentation

    Documentation

    Full doc comments, making a nice useful Rustdoc page. Users should be able to use this documentation alone to learn the library.

    documentation 
    opened by deciduously 1
  • Tests

    Tests

    null

    opened by deciduously 1
  • Scheduler tests

    Scheduler tests

    Once integration testing is complete, the basic planned functionality is ready.

    opened by deciduously 1
  • CFFI

    CFFI

    Commented-out lines in examples/ffi/c/main.c are non-functional.

    enhancement 
    opened by deciduously 1
  • Finish up basic functionality

    Finish up basic functionality

    null

    opened by deciduously 0
  • cbindgen

    cbindgen

    Use it for the C++ example. The C one can stay as a "raw" example with externs and everything.

    opened by deciduously 0
  • More FFI examples

    More FFI examples

    Demonstrate how to ergonomically wrap the CFFI in higher-level languages.

    documentation good first issue 
    opened by deciduously 0
  • Run jobs in background processes

    Run jobs in background processes

    This will seriously help usability - right now, running jobs block the schedule until complete. These should be spawned in a background thread.

    opened by deciduously 0
  • Complete testing

    Complete testing

    Basic functionality and API is tested, but not all possible interactions.

    enhancement 
    opened by deciduously 0
  • Jobs with return values

    Jobs with return values

    null

    enhancement 
    opened by deciduously 0
  • Better until()

    Better until()

    Requires a chrono::DateTime<Local> - should be able to parse from a flexible string.

    enhancement good first issue 
    opened by deciduously 0
  • Weekly intervals greater than 1

    Weekly intervals greater than 1

    Currently, weekday-specified jobs must run every single week. Should we support every 2nd or 3rd week, too?

    enhancement good first issue 
    opened by deciduously 0
  • Sub-second timing

    Sub-second timing

    Currently, only goes down to seconds. Should this support milliseconds?

    enhancement 
    opened by deciduously 0
Releases(0.1.1)
Owner
Ben Lovy
Rust is pretty cool.
Ben Lovy
delicate A lightweight and distributed task scheduling platform written in rust

A lightweight and distributed task scheduling platform written in rust.

BinCheng 166 Sep 15, 2021
Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.

delay-timer Time-manager of delayed tasks. Like crontab, but synchronous asynchronous tasks are possible, and dynamic add/cancel/remove is supported.

BinCheng 114 Sep 9, 2021
Ergo is a low-code IFTTT/Zapier style application, built with Rust and Svelte

Ergo is a low-code IFTTT/Zapier style application, built with Rust and Svelte. Tasks are customizable with Javascript and can contain state machines for more advanced task handling.

Daniel Imfeld 45 Sep 16, 2021
Task runner and process manager for Rust

Steward Task runner and process manager for Rust. If you're not happy managing your infrastructure with a pile of bash scripts, this crate might be he

Alex Fedoseev 16 Sep 1, 2021
Fang - Background job processing library for Rust.

Fang Background job processing library for Rust. Currently, it uses Postgres to store state. But in the future, more backends will be supported.

Ayrat Badykov 62 Sep 13, 2021
Wait for async tasks

taskwait Runtime agnostic way of waiting for async tasks. Features Done: Support for golang's WaitGroup.Add & WaitGroup.Done Done: Support for RAII ba

null 10 May 2, 2021