/tokio-cron-async

🕒 CRON scheduler using Tokio for async jobs.

Primary LanguageRust

🕒 tokio-cron-async

CRON scheduler using Tokio for async jobs.

use tokio_cron_async::JobSchedule;
use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let schedule: JobSchedule = JobSchedule::new();

    schedule.add("1/10 * * * * *".to_string(), Box::new(|_uuid| {
        Box::pin(async move {
            println!("10 seconds have passed");
            sleep(Duration::from_secs(10)).await;
        })
    }))
    .await?;

    tokio::spawn(schedule.run()).await?;

    Ok(())
}

Motivation

Why?

I wanted something like mvniekerk/tokio-cron-scheduler, but with async jobs.

Why weren't this contributed to the mentioned repo?

It's a bit unclear wether the API from this repo is suitable for different use-cases and project I've built this for can tolerate potential risk. It might be contributed there at later stages.

Inspiration