Skip to content

Commit

Permalink
typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
deciduously committed Sep 19, 2024
1 parent 33c6b13 commit 07f3597
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 272 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = []
ffi = []

[dependencies]
chrono = "0.4"
jiff = "0.1"
libc = "0.2"
rand = "0.8"
regex = "1.5"
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ Documentation can be found on [docs.rs](https://docs.rs/skedge).
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.

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

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

Expand All @@ -29,10 +29,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
every(2)
.to(8)?
.seconds()?
.until(Local::now() + chrono::Duration::seconds(30))?
.until(Zoned::now() + Duration::from_secs(30))?
.run_one_arg(&mut schedule, greet, "Cool Person")?;

let now = Local::now();
let now = Zoned::now();
println!("Starting at {now}");
loop {
if let Err(e) = schedule.run_pending() {
Expand Down
8 changes: 4 additions & 4 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Some more varied usage examples.

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

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

Expand Down Expand Up @@ -41,7 +41,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
every(2)
.to(8)?
.seconds()?
.until(Local::now() + chrono::Duration::days(5))?
.until(Zoned::now().checked_add(5.seconds()).unwrap())?
.run_six_args(
&mut schedule,
flirt,
Expand All @@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"foraged chanterelle croque monsieur",
)?;

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

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

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

Expand All @@ -16,10 +16,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
every(2)
.to(8)?
.seconds()?
.until(Local::now() + chrono::Duration::seconds(30))?
.until(Zoned::now().checked_add(30.seconds()).unwrap())?
.run_one_arg(&mut schedule, greet, "Cool Person")?;

let now = Local::now();
let now = Zoned::now();
println!("Starting at {now}");
loop {
if let Err(e) = schedule.run_pending() {
Expand Down
19 changes: 7 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module defines the error type and Result alias.
use crate::Unit;
use chrono::Weekday;
use jiff::civil::Weekday;
use thiserror::Error;

#[derive(Debug, PartialEq, Error)]
Expand All @@ -17,15 +17,15 @@ pub enum Error {
#[error("Invalid unit (valid units are `days`, `hours`, and `minutes`)")]
InvalidUnit,
#[error("Invalid hour ({0} is not between 0 and 23)")]
InvalidHour(u32),
InvalidHour(i8),
#[error("Invalid time format for daily job (valid format is HH:MM(:SS)?)")]
InvalidDailyAtStr,
#[error("Invalid time format for hourly job (valid format is (MM)?:SS)")]
InvalidHourlyAtStr,
#[error("Invalid time format for minutely job (valid format is :SS)")]
InvalidMinuteAtStr,
#[error("Invalid hms values for NaiveTime ({0},{1},{2})")]
InvalidNaiveTime(u32, u32, u32),
#[error("Invalid hms values for civil::Time ({0},{1},{2})")]
InvalidCivilTime(i8, i8, i8),
#[error("Invalid string format for until()")]
InvalidUntilStr,
#[error("Cannot schedule a job to run until a time in the past")]
Expand All @@ -42,9 +42,9 @@ pub enum Error {
StartDayError,
#[error("{0}")]
ParseInt(#[from] std::num::ParseIntError),
#[error("Scheduling jobs on {0} is only allowed for weekly jobs. Using specific days on a job scheduled to run every 2 or more weeks is not supported")]
#[error("Scheduling jobs on {0:?} is only allowed for weekly jobs. Using specific days on a job scheduled to run every 2 or more weeks is not supported")]
Weekday(Weekday),
#[error("Cannot schedule {0} job, already scheduled for {1}")]
#[error("Cannot schedule {0:?} job, already scheduled for {1:?}")]
WeekdayCollision(Weekday, Weekday),
#[error("Invalid unit without specifying start day")]
UnspecifiedStartDay,
Expand All @@ -56,15 +56,10 @@ pub(crate) fn unit_error(intended: Unit, existing: Unit) -> Error {
}

/// Construct a new invalid hour error.
pub(crate) fn invalid_hour_error(hour: u32) -> Error {
pub(crate) fn invalid_hour_error(hour: i8) -> Error {
Error::InvalidHour(hour)
}

/// Concstruct a new invalid HMS error.
pub(crate) fn invalid_hms_error(hour: u32, minute: u32, second: u32) -> Error {
Error::InvalidNaiveTime(hour, minute, second)
}

/// Construct a new Interval error.
pub(crate) fn interval_error(interval: Unit) -> Error {
Error::Interval(interval)
Expand Down
Loading

0 comments on commit 07f3597

Please sign in to comment.