Skip to main content

Crate cron_task_scheduler

Crate cron_task_scheduler 

Source
Expand description

A high-performance async cron scheduler.

§Example

use cronscheduler::{SchedulerActor, WorkerActor, HttpTask, SimpleLoggingTask, CommandLineTask, ExecutionPolicy, SchedulingPolicy};
use std::sync::Arc;
use tokio::sync::mpsc;
use reqwest::Client;

#[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);

    // Async task
    let log_task = Arc::new(SimpleLoggingTask { id: "heartbeat".to_string() });
    scheduler.add_task(log_task, "*/5 * * * * *", ExecutionPolicy::Parallel, SchedulingPolicy::FirstInFirstOut, 0)?;

    // Blocking task
    let ping_task = Arc::new(CommandLineTask {
        id: "ping-google".to_string(),
        command: "ping".to_string(),
        args: vec!["-c".to_string(), "1".to_string(), "8.8.8.8".to_string()],
    });
    scheduler.add_task(ping_task, "*/30 * * * * *", ExecutionPolicy::SkipIfRunning, SchedulingPolicy::FirstInFirstOut, 0)?;

    Ok(())
}

Re-exports§

pub use actor::scheduler::SchedulerActor;
pub use actor::worker::WorkerActor;
pub use cron_parser::CronParser;
pub use http_tasks::HttpTask;
pub use http_tasks::SimpleLoggingTask;
pub use http_tasks::CommandLineTask;
pub use models::ExecutionPolicy;
pub use models::ReactiveTask;
pub use models::TaskContext;
pub use models::SchedulingPolicy;
pub use models::TaskType;

Modules§

actor
cron_parser
http_tasks
models

Functions§

run
A high performance async cron scheduler runner.