1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//! Azoth Scheduler
//!
//! A cron-like task scheduling system for Azoth projects.
//!
//! # Overview
//!
//! The scheduler provides task scheduling capabilities with:
//! - Cron expressions for recurring tasks
//! - Interval-based scheduling
//! - One-time tasks at specific times
//! - Immediate execution (job queue)
//! - Configurable concurrency
//! - Automatic retries with exponential backoff
//!
//! # Architecture
//!
//! The scheduler follows Azoth's event-sourcing architecture:
//!
//! 1. **Schedule Events**: Tasks are scheduled by writing events to the canonical store
//! 2. **Projection**: A SQLite projection tracks task state and next run times
//! 3. **Scheduler Loop**: Continuously polls for due tasks
//! 4. **Task Handlers**: Execute tasks and produce events
//! 5. **Event Handlers**: Process task result events
//!
//! # Example
//!
//! ```ignore
//! use azoth_scheduler::prelude::*;
//! use std::sync::Arc;
//!
//! // Define a task handler
//! struct ReportHandler;
//!
//! impl TaskHandler for ReportHandler {
//! fn task_type(&self) -> &str {
//! "generate_report"
//! }
//!
//! fn execute(&self, ctx: &TaskContext, payload: &[u8]) -> Result<TaskEvent> {
//! // Execute task logic
//! Ok(TaskEvent {
//! event_type: "report_generated".to_string(),
//! payload: vec![],
//! })
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let db = Arc::new(AzothDb::open("./data")?);
//! let conn = Arc::new(Connection::open("./projection.db")?);
//!
//! // Create scheduler
//! let scheduler = Scheduler::builder(db.clone())
//! .with_task_handler(ReportHandler)
//! .with_poll_interval(Duration::from_secs(1))
//! .build(conn)?;
//!
//! // Schedule a task
//! scheduler.schedule_task(
//! ScheduleTaskRequest::builder("daily-report")
//! .task_type("generate_report")
//! .cron("0 0 * * *") // Daily at midnight
//! .payload(vec![])
//! .build()?
//! )?;
//!
//! // Run scheduler
//! scheduler.run().await?;
//! Ok(())
//! }
//! ```
// Re-export main types
pub use SchedulerConfig;
pub use ;
pub use SchedulerEventApplier;
pub use SchedulerEvent;
pub use ;
pub use Schedule;
pub use ;
pub use ;