Crates.io | tokio-simple-scheduler |
lib.rs | tokio-simple-scheduler |
version | 0.1.2 |
source | src |
created_at | 2022-08-26 09:51:37.718541 |
updated_at | 2022-11-19 18:35:49.368989 |
description | A very simple scheduler for Tokio |
homepage | |
repository | https://github.com/brettmayson/tokio-simple-scheduler |
max_upload_size | |
id | 652697 |
size | 20,026 |
I needed a very basic scheduler with no features, so here it is.
use std::time::Duration;
use chrono::Utc;
use tokio_simple_scheduler::{Job, Scheduler};
#[tokio::main]
async fn main() {
let mut scheduler = Scheduler::default();
scheduler.add(
Job::new("every 2", "*/2 * * * * *", || {
Box::pin(async {
println!("{:?} - Every 2 seconds", Utc::now());
})
})
.unwrap(),
);
scheduler.add(
Job::new("every 4", "*/4 * * * * *", || {
Box::pin(async {
println!("{:?} - Every 4 seconds", Utc::now());
})
})
.unwrap(),
);
scheduler.add(
Job::new("every 5", "*/5 * * * * *", || {
Box::pin(async {
println!("{:?} - Every 5 seconds", Utc::now());
})
})
.unwrap(),
);
scheduler.add(
Job::new("every 10", "*/10 * * * * *", || {
Box::pin(async {
println!("{:?} - Every 10 seconds", Utc::now());
})
})
.unwrap(),
);
scheduler.add(
Job::new("every 30", "*/30 * * * * *", || {
Box::pin(async {
println!("this job");
tokio::time::sleep(Duration::from_secs(3)).await;
println!("takes a few");
tokio::time::sleep(Duration::from_secs(3)).await;
println!("seconds to run");
})
})
.unwrap(),
);
scheduler.start().await;
}
It doesn't do anything else.