Skip to content

Commit

Permalink
0.1.0 (#14)
Browse files Browse the repository at this point in the history
* Add more documentation examples

* Args up through 6

* Fix readme example

* Update doc badge
  • Loading branch information
deciduously committed Sep 8, 2021
1 parent 7c2aa0b commit 5cf8f7e
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "skedge"
description = "Ergonomic single-process job scheduling for Rust programs."
version = "0.0.6"
version = "0.1.0"
edition = "2018"
authors = ["Ben Lovy <ben@deciduously.com>"]
documentation = "https://docs.rs/skedge"
Expand Down
23 changes: 6 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

[![Crates.io](https://img.shields.io/crates/v/skedge.svg)](https://crates.io/crates/skedge)
[![rust action](https://github.com/deciduously/skedge/actions/workflows/rust.yml/badge.svg)](https://github.com/deciduously/skedge/actions/workflows/rust.yml)
[![docs.rs](https://img.shields.io/docsrs/skedge)](https://docs.rs/skedge/)
[![docs.rs](https://img.shields.io/docsrs/skedge/0.1.0)](https://docs.rs/skedge/0.1.0)

Rust single-process scheduling. Ported from [`schedule`](https://github.com/dbader/schedule) for Python, in turn inspired by [`clockwork`](https://github.com/Rykian/clockwork) (Ruby), and ["Rethinking Cron"](https://adam.herokuapp.com/past/2010/4/13/rethinking_cron/) by [Adam Wiggins](https://github.com/adamwiggins).

**NOTE**: This library is currently limited to jobs which take no arguments and return nothing.

## Usage

Documentation can be found on [docs.rs](https://docs.rs/skedge).
Expand All @@ -16,30 +14,22 @@ This library uses the Builder pattern to define jobs. Instantiate a fresh `Sche

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

fn job() {
println!("Hello, it's {}!", Local::now());
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(10).seconds()?.run(&mut schedule, job)?;
every(10).minutes()?.run(&mut schedule, job)?;
every_single().hour()?.run(&mut schedule, job)?;
every_single().day()?.at("10:30")?.run(&mut schedule, job);
every(5).to(10)?.minutes()?.run(&mut schedule, job);
every_single().monday()?.run(&mut schedule, job);
every_single().wednesday()?.at("13:15")?.run(&mut schedule, job);
every_single().minute()?.at(":17")?.run(&mut schedule, job);
every(2)
.to(8)?
.seconds()?
.until(Local::now() + chrono::Duration::seconds(30))?
.run(&mut schedule, job)?;
.run_one_arg(&mut schedule, greet, "Good-Looking")?;

println!("Starting at {}", Local::now());
loop {
Expand All @@ -51,7 +41,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
```

Try `cargo run --example basic` to see it in action.
Check out the [example script](https://github.com/deciduously/skedge/blob/main/examples/basic.rs) to see more configuration options. Try `cargo run --example readme` or `cargo run --example basic` to see it in action.

## Development

Expand All @@ -73,5 +63,4 @@ Clone this repo. See [`CONTRIBUTING.md`](https://github.com/deciduously/skedge/

#### Development-Only

* [mockall](https://github.com/asomers/mockall) - Mock objects
* [pretty_assertions](https://github.com/colin-kiegel/rust-pretty-assertions) - Colorful assertion output
35 changes: 31 additions & 4 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,59 @@
// Some more varied usage examples.

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

fn job() {
println!("Hello, it's {}!", Local::now());
println!("Hello, it's {}!", Local::now().to_rfc2822());
}

fn flirt(name: &str, time: &str, hour: u8, jackpot: f32, restaurant: &str, meal: &str) {
println!(
"Hello, {}! What are you doing {}? I'm free around {}. \
I just won ${:.*} off a scratch ticket, you can get anything you want. \
Have you ever been to {}? They're getting rave reviews over their {}.",
name, time, hour, 2, jackpot, restaurant, meal
);
}

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

every(10).seconds()?.run(&mut schedule, job)?;

every(10).minutes()?.run(&mut schedule, job)?;

every_single().hour()?.run(&mut schedule, job)?;

every_single().day()?.at("10:30")?.run(&mut schedule, job)?;

every(5).to(10)?.minutes()?.run(&mut schedule, job)?;

every_single().monday()?.run(&mut schedule, job)?;

every_single()
.wednesday()?
.at("13:15")?
.run(&mut schedule, job)?;

every(2)
.to(8)?
.seconds()?
.until(Local::now() + chrono::Duration::seconds(30))?
.run(&mut schedule, job)?;
.until(Local::now() + chrono::Duration::days(5))?
.run_six_args(
&mut schedule,
flirt,
"Good-Looking",
"Friday",
7,
40.,
"Dorsia",
"foraged chanterelle croque monsieur",
)?;

println!("Starting at {}", Local::now());
println!("Starting at {}", Local::now().to_rfc3339());
loop {
if let Err(e) = schedule.run_pending() {
eprintln!("Error: {}", e);
Expand Down
28 changes: 28 additions & 0 deletions examples/readme.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// This is the exact code from the README.md example

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));
}
}
Loading

0 comments on commit 5cf8f7e

Please sign in to comment.