armature_distributed/lib.rs
1//! Distributed Systems Support for Armature
2//!
3//! This crate provides distributed coordination primitives.
4//!
5//! ## Features
6//!
7//! - **Distributed Locks** - Redis-based distributed locks
8//! - **Leader Election** - Automatic leader election with callbacks
9//! - **TTL Management** - Automatic lock/leadership renewal
10//! - **RAII Pattern** - Automatic cleanup on drop
11//!
12//! ## Quick Start
13//!
14//! ### Distributed Locks
15//!
16//! ```rust,ignore
17//! use armature_distributed::*;
18//! use std::time::Duration;
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//! // Connect to Redis
23//! let client = redis::Client::open("redis://127.0.0.1/")?;
24//! let conn = client.get_connection_manager().await?;
25//!
26//! // Create a distributed lock
27//! let lock = RedisLock::new("my-resource", Duration::from_secs(30), conn);
28//!
29//! // Acquire the lock
30//! let guard = lock.acquire().await?;
31//!
32//! // Critical section
33//! println!("Lock acquired, doing work...");
34//!
35//! // Lock is automatically released when guard is dropped
36//! drop(guard);
37//!
38//! Ok(())
39//! }
40//! ```
41//!
42//! ### Leader Election
43//!
44//! ```rust,ignore
45//! use armature_distributed::*;
46//! use std::sync::Arc;
47//! use std::time::Duration;
48//!
49//! #[tokio::main]
50//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
51//! let client = redis::Client::open("redis://127.0.0.1/")?;
52//! let conn = client.get_connection_manager().await?;
53//!
54//! let election = Arc::new(
55//! LeaderElection::new("my-service-leader", Duration::from_secs(30), conn)
56//! .on_elected(|| async {
57//! println!("I am the leader!");
58//! })
59//! .on_revoked(|| async {
60//! println!("I lost leadership");
61//! })
62//! );
63//!
64//! // Start election (runs in background)
65//! let election_clone = election.clone();
66//! tokio::spawn(async move {
67//! election_clone.start().await
68//! });
69//!
70//! // Check leadership status
71//! if election.is_leader() {
72//! println!("This node is the leader");
73//! }
74//!
75//! Ok(())
76//! }
77//! ```
78
79pub mod leader;
80pub mod lock;
81
82pub use leader::{LeaderElection, LeaderElectionBuilder, LeaderError};
83pub use lock::{DistributedLock, LockBuilder, LockError, LockGuard, RedisLock};
84
85#[cfg(test)]
86mod tests {
87 #[test]
88 fn test_module_exports() {
89 // Ensure module compiles
90 }
91}