diff --git a/Cargo.lock b/Cargo.lock index ffdca5b..3e57207 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,7 +45,7 @@ dependencies = [ [[package]] name = "async_job" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-trait", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 9e029c6..449066d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "async_job" -version = "0.1.0" +version = "0.1.1" edition = "2021" -description = "Simple async cron jobs for Rust" +description = "Simple async cron job crate for Rust" repository = "https://github.com/spider-rs/async_job" readme = "README.md" keywords = ["crawler", "spider"] @@ -16,4 +16,9 @@ chrono = "0.4.31" cron = "0.12.0" lazy_static = "1.4.0" log = "0.4.20" -tokio = { version = "^1.34.0", features = [ "rt-multi-thread", "macros", "time", "parking_lot" ] } +tokio = { version = "^1.34.0", features = [ "macros", "time", "parking_lot" ] } + +[features] +default = ["rt-multi-thread"] +rt = ["tokio/rt"] +rt-multi-thread = ["tokio/rt-multi-thread"] \ No newline at end of file diff --git a/README.md b/README.md index e6a8070..8197900 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # async_job -A simple trait that allows you to attach cron jobs to anything in Rust. +A simple trait for async cron jobs in Rust. ## Getting Started @@ -25,6 +25,13 @@ impl Job for ExampleJob { } ``` +If you need to use a single threaded env disable the default feature and set the feature `rt`, + +## Feature Flags + +1. `rt`: Single threaded tokio runtime. +1. `rt-multi-thread`: Multi threaded tokio runtime. Enabled by default + ## Examples Run the example with `cargo run --example example` diff --git a/src/lib.rs b/src/lib.rs index 486765e..850ba51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! # async_job: a simple async cron runner //! //! Use the `Job` trait to create your cron job struct, pass it to the `Runner` and then start it via `run()` method. -//! Runner will spawn new thread where it will start looping through the jobs and will run their handle +//! Runner will spawn new async task where it will start looping through the jobs and will run their handle //! method once the scheduled time is reached. //! //! If your OS has enough threads to spare each job will get its own thread to execute, if not it will be @@ -12,8 +12,7 @@ //! ## Example //! ``` //! use async_job::{Job, Runner, Schedule, async_trait}; -//! use std::thread; -//! use std::time::Duration; +//! use tokio::time::Duration; //! use tokio; //! //! struct ExampleJob; @@ -36,7 +35,7 @@ //! //! println!("Starting the Runner for 20 seconds"); //! runner = runner.run().await; -//! thread::sleep(Duration::from_millis(20 * 1000)); +//! tokio::time::sleep(Duration::from_millis(20 * 1000)).await; //! //! println!("Stopping the Runner"); //! runner.stop().await;