Crates.io | grizzly_scheduler |
lib.rs | grizzly_scheduler |
version | 0.2.0 |
source | src |
created_at | 2024-02-12 16:19:05.576053 |
updated_at | 2024-10-09 10:39:36.086715 |
description | A scheduler for running async tasks using cron expressions. It is built on top of tokio. Tasks can be parallel or sequential. Fuzzy random offset can be added to the cron expression. |
homepage | https://github.com/ivan-brko/grizzly_scheduler |
repository | https://github.com/ivan-brko/grizzly_scheduler |
max_upload_size | |
id | 1137138 |
size | 44,765 |
A simple and easy to use scheduler, built on top of Tokio, that allows you to schedule async tasks using cron expressions (with optional random fuzzy offsets for each trigger).
Tasks can be of two types:
use std::sync::Arc;
use grizzly_scheduler::scheduler::Scheduler;
let scheduler = grizzly_scheduler::scheduler::Scheduler::new_in_utc();
let important_shared_state = Arc::new(5);
let cloned_state = important_shared_state.clone();
let job_id = scheduler.schedule_parallel_job(
"*/5 * * * * *", // run the job on every second divisible by 5 of every minute
Some("Example Parallel Job".to_string()), // this name will appear in the tracing logs
Some("Some Category".to_string()), // we can use this to stop all tasks of single category
Some(chrono::Duration::seconds(2)), // we want the fuzzy effect of maximally +/-2 seconds
move ||
{
let cloned_state = cloned_state.clone();
async move {
tracing::info!("We are using our important shared state! {}", cloned_state);
}
},
).unwrap();
scheduler.start().unwrap();
This project is licensed under MIT license, which can be found in the LICENSE file.
All contributions are welcome! Please feel free to open an issue or a pull request.