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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Job queue and background processing for Armature framework.
//!
//! Provides a robust job queue system with:
//! - 📦 Redis-backed persistence
//! - 🔄 Automatic retries with exponential backoff
//! - ⭐ Job priorities
//! - ⏰ Delayed/scheduled jobs
//! - 💀 Dead letter queue
//! - 📊 Job progress tracking
//! - 🎯 Multiple queues
//! - 👷 Worker pools
//! - ♻️ Stale-claim reclaim for jobs orphaned by a crashed worker
//!
//! ## Delivery semantics
//!
//! Delivery is **at-least-once**, so job handlers must be idempotent. A worker
//! that is SIGKILLed (or whose handler task panics) after its side effects but
//! before `complete()` is indistinguishable from one that died before them, so
//! [`Queue::reclaim_stale`] returns the job to its pending queue and it runs
//! again. [`Worker::start`] runs that reaper in the background on
//! [`WorkerConfig::visibility_timeout`]; without it such a job would sit in the
//! `processing` set forever, never retried and never dead-lettered.
//!
//! ## Quick Start - Job Creation
//!
//! ```
//! use armature_queue::{Job, JobData, JobPriority};
//! use serde_json::json;
//!
//! let job = Job::new(
//! "emails",
//! "send_welcome",
//! json!({"to": "user@example.com"})
//! );
//!
//! assert_eq!(job.queue, "emails");
//! assert_eq!(job.job_type, "send_welcome");
//! assert_eq!(job.priority, JobPriority::Normal);
//! ```
//!
//! ## Job Priorities
//!
//! ```
//! use armature_queue::{Job, JobData, JobPriority};
//! use serde_json::json;
//!
//! // Create high priority job
//! let urgent = Job::new(
//! "tasks",
//! "urgent_task",
//! json!({})
//! ).with_priority(JobPriority::High);
//!
//! // Create low priority job
//! let background = Job::new(
//! "tasks",
//! "cleanup",
//! json!({})
//! ).with_priority(JobPriority::Low);
//!
//! assert_eq!(urgent.priority, JobPriority::High);
//! assert_eq!(background.priority, JobPriority::Low);
//! assert!(urgent.priority > background.priority);
//! ```
//!
//! ## Delayed Jobs
//!
//! ```
//! use armature_queue::Job;
//! use serde_json::json;
//! use chrono::Duration;
//!
//! // Schedule job to run in 1 hour
//! let scheduled = Job::new(
//! "emails",
//! "reminder",
//! json!({"message": "Don't forget!"})
//! ).schedule_after(Duration::hours(1));
//!
//! assert!(scheduled.scheduled_at.is_some());
//! ```
//!
//! ## Queue Configuration
//!
//! ```
//! use armature_queue::QueueConfig;
//! use std::time::Duration;
//!
//! let config = QueueConfig::new("redis://localhost:6379", "emails")
//! .with_key_prefix("myapp:queue:emails")
//! .with_max_size(10000)
//! .with_retention_time(Duration::from_secs(86400));
//!
//! assert_eq!(config.queue_name, "emails");
//! assert_eq!(config.max_size, 10000);
//! assert_eq!(config.retention_time, Duration::from_secs(86400));
//! ```
//!
//! ## Complete Example
//!
//! ```no_run
//! use armature_queue::*;
//!
//! #[tokio::main]
//! async fn main() -> Result<(), QueueError> {
//! // Create a queue
//! let queue = Queue::new("redis://localhost:6379", "default").await?;
//!
//! // Enqueue a job
//! let job_id = queue.enqueue(
//! "send_email",
//! serde_json::json!({
//! "to": "user@example.com",
//! "subject": "Hello"
//! })
//! ).await?;
//!
//! // Process jobs
//! let mut worker = Worker::new(queue);
//! worker
//! .register_handler("send_email", |job| async move {
//! // Send email logic
//! Ok(())
//! })
//! .await;
//!
//! worker.start().await?;
//!
//! Ok(())
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
/// Re-export commonly used types