Skip to main content

cron_task_scheduler/
lib.rs

1//! A high-performance async cron scheduler.
2//!
3//! # Example
4//!
5//! ```
6//! use cronscheduler::{SchedulerActor, WorkerActor, HttpTask, SimpleLoggingTask, CommandLineTask, ExecutionPolicy, SchedulingPolicy};
7//! use std::sync::Arc;
8//! use tokio::sync::mpsc;
9//! use reqwest::Client;
10//!
11//! #[tokio::main]
12//! async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
13//!     let (worker_tx, worker_rx) = mpsc::channel(100);
14//!     let worker = WorkerActor::new(worker_rx);
15//!     tokio::spawn(async move { worker.run().await; });
16//!
17//!     let mut scheduler = SchedulerActor::new(worker_tx);
18//!
19//!     // Async task
20//!     let log_task = Arc::new(SimpleLoggingTask { id: "heartbeat".to_string() });
21//!     scheduler.add_task(log_task, "*/5 * * * * *", ExecutionPolicy::Parallel, SchedulingPolicy::FirstInFirstOut, 0)?;
22//!
23//!     // Blocking task
24//!     let ping_task = Arc::new(CommandLineTask {
25//!         id: "ping-google".to_string(),
26//!         command: "ping".to_string(),
27//!         args: vec!["-c".to_string(), "1".to_string(), "8.8.8.8".to_string()],
28//!     });
29//!     scheduler.add_task(ping_task, "*/30 * * * * *", ExecutionPolicy::SkipIfRunning, SchedulingPolicy::FirstInFirstOut, 0)?;
30//!
31//!     Ok(())
32//! }
33//! ```
34
35pub mod actor;
36pub mod cron_parser;
37pub mod http_tasks;
38pub mod models;
39
40pub use actor::scheduler::SchedulerActor;
41pub use actor::worker::WorkerActor;
42pub use cron_parser::CronParser;
43pub use http_tasks::{HttpTask, SimpleLoggingTask, CommandLineTask};
44pub use models::{ExecutionPolicy, ReactiveTask, TaskContext, SchedulingPolicy, TaskType};
45
46/// A high performance async cron scheduler runner.
47///
48/// This is a convenience function to demonstrate library usage.
49pub fn run() {
50    println!("Cron Task Scheduler Library initialized.");
51}