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
//! Background job processing system using acton-reactive actors.
//!
//! This module provides a robust background job processing system with:
//! - Type-safe job definitions via the [`Job`] trait
//! - **Actor-based architecture** using acton-reactive v5
//! - **In-memory priority queue** with fast synchronous operations (`mutate_on`)
//! - **Concurrent Redis persistence** using async I/O (`act_on`)
//! - Automatic retry with exponential backoff
//! - Dead letter queue for failed jobs
//! - Priority-based execution
//! - Graceful shutdown support
//! - Job scheduling (cron, delayed, recurring)
//! - Comprehensive observability with OpenTelemetry support
//!
//! # Architecture
//!
//! The job system uses acton-reactive's actor model with two handler types:
//!
//! ## `mutate_on` Handlers (Synchronous State Mutations)
//! - **EnqueueJob**: Adds jobs to the in-memory priority queue
//! - Fast, synchronous operations that update agent state
//! - Immediate reply to caller
//!
//! ## `act_on` Handlers (Concurrent Async I/O)
//! - **PersistJob**: Writes job data to Redis (runs concurrently)
//! - **MarkJobCompleted**: Updates job status in Redis
//! - **MarkJobFailed**: Records failures for retry logic
//! - **MoveToDeadLetterQueue**: Archives permanently failed jobs
//! - Non-blocking, can run in parallel with other operations
//!
//! This separation ensures:
//! - **Fast enqueue** (in-memory operation returns immediately)
//! - **Durable persistence** (Redis writes happen asynchronously)
//! - **No blocking** (I/O doesn't block the agent's message processing)
//!
//! # Example
//!
//! ```rust
//! use acton_htmx::jobs::{Job, JobResult};
//! use async_trait::async_trait;
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, Clone, Serialize, Deserialize)]
//! pub struct WelcomeEmailJob {
//! user_id: i64,
//! email: String,
//! }
//!
//! #[async_trait]
//! impl Job for WelcomeEmailJob {
//! type Result = ();
//!
//! async fn execute(&self) -> JobResult<Self::Result> {
//! // Send welcome email
//! println!("Sending welcome email to {} (user {})", self.email, self.user_id);
//! Ok(())
//! }
//!
//! fn max_retries(&self) -> u32 {
//! 3
//! }
//! }
//! ```
pub use ;
pub use JobContext;
pub use ;
pub use ;
pub use ;
pub use JobMetricsCollector;
pub use JobSchedule;
pub use JobStatus;
// Re-export agent components
pub use JobAgent;
// Test utilities are now in the testing module
// Re-export for backward compatibility
pub use crate;