Cron Task Scheduler Library 'cronscheduler'
A high performance async cron scheduler for Rust.
Features
- Async First: Built on top of Tokio.
- Actor Model: Uses actors for task scheduling and execution isolation.
- Cron Expressions: Supports standard cron expressions via the
cron crate.
- Execution Policies: Control how tasks behave when already running (Skip, Parallel, etc.).
Installation
Add this to your Cargo.toml:
[dependencies]
cronscheduler = "0.1.6"
Quick Start
use cronscheduler::{SchedulerActor, WorkerActor, SimpleLoggingTask, ExecutionPolicy};
use std::sync::Arc;
use tokio::sync::mpsc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (worker_tx, worker_rx) = mpsc::channel(100);
let worker = WorkerActor::new(worker_rx);
tokio::spawn(async move {
worker.run().await;
});
let mut scheduler = SchedulerActor::new(worker_tx);
let log_task = Arc::new(SimpleLoggingTask {
id: "heartbeat".to_string(),
});
scheduler.add_task(log_task, "*/5 * * * * *", ExecutionPolicy::Parallel)?;
scheduler.start_all().await;
tokio::signal::ctrl_c().await?;
Ok(())
}
License
Licensed under Apache License, Version 2.0.