celers_beat/lib.rs
1//! Periodic task scheduler (Celery Beat equivalent)
2//!
3//! This crate provides scheduled task execution with various schedule types
4//! and persistent state management.
5//!
6//! # Schedule Types
7//!
8//! - **Interval**: Execute every N seconds
9//! - **Crontab**: Execute based on cron expression (requires `cron` feature)
10//! - **Solar**: Execute at solar events (sunrise, sunset) (requires `solar` feature)
11//! - **OneTime**: Execute once at a specific timestamp (auto-cleanup after execution)
12//!
13//! # Persistence
14//!
15//! The scheduler supports automatic state persistence to JSON files, preserving
16//! schedules and execution history across restarts:
17//!
18//! ```no_run
19//! use celers_beat::{BeatScheduler, Schedule, ScheduledTask};
20//!
21//! // Load scheduler from file (or create new if file doesn't exist)
22//! let mut scheduler = BeatScheduler::load_from_file("schedules.json").unwrap();
23//!
24//! // Add tasks - automatically saved to file
25//! let task = ScheduledTask::new("send_report".to_string(), Schedule::interval(60));
26//! scheduler.add_task(task).unwrap();
27//!
28//! // State persists across restarts
29//! ```
30//!
31//! # Basic Example
32//!
33//! ```ignore
34//! use celers_beat::{Schedule, ScheduledTask};
35//!
36//! let schedule = Schedule::interval(60); // Every 60 seconds
37//! let task = ScheduledTask::new("send_report".to_string(), schedule);
38//! ```
39
40use std::sync::Arc;
41
42pub mod alert;
43pub mod config;
44pub mod heartbeat;
45pub mod history;
46pub mod lock;
47pub mod schedule;
48pub mod schedule_ext;
49pub mod scheduler;
50pub mod scheduler_ext;
51pub mod task;
52pub mod wfq;
53
54#[cfg(test)]
55mod tests;
56
57// Re-export main types
58pub use alert::*;
59pub use config::*;
60pub use heartbeat::{BeatHeartbeat, BeatRole, HeartbeatConfig, HeartbeatInfo, HeartbeatStats};
61pub use history::*;
62pub use lock::*;
63pub use schedule::*;
64pub use schedule_ext::*;
65pub use scheduler::*;
66pub use scheduler_ext::*;
67pub use task::*;
68pub use wfq::*;
69
70/// Failure notification callback type
71///
72/// Called when a task execution fails. Receives the task name and error message.
73pub type FailureCallback = Arc<dyn Fn(&str, &str) + Send + Sync>;