Skip to content

Commit

Permalink
feat(runtime): add single threaded runtime option
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Nov 30, 2023
1 parent f4069a6 commit f7d589b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand All @@ -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"]
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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`
7 changes: 3 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit f7d589b

Please sign in to comment.