tokio-simple-scheduler

Crates.iotokio-simple-scheduler
lib.rstokio-simple-scheduler
version0.1.2
sourcesrc
created_at2022-08-26 09:51:37.718541
updated_at2022-11-19 18:35:49.368989
descriptionA very simple scheduler for Tokio
homepage
repositoryhttps://github.com/brettmayson/tokio-simple-scheduler
max_upload_size
id652697
size20,026
(BrettMayson)

documentation

README

Tokio Simple Scheduler

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.

Commit count: 6

cargo fmt