forked from
smokesignal.events/quickdid
QuickDID is a high-performance AT Protocol identity resolution service written in Rust. It provides handle-to-DID resolution with Redis-backed caching and queue processing.
1//! Queue adapter system for work queue abstraction.
2//!
3//! This module provides a generic trait and implementations for queue adapters
4//! that can be used with any work type for handle resolution and other tasks.
5//!
6//! # Architecture
7//!
8//! The queue system is designed with the following components:
9//!
10//! - **Trait**: `QueueAdapter` - Common interface for all queue implementations
11//! - **Implementations**:
12//! - `MpscQueueAdapter` - In-memory MPSC channel-based queue
13//! - `RedisQueueAdapter` - Distributed Redis-backed queue
14//! - `SqliteQueueAdapter` - Persistent SQLite-backed queue
15//! - `NoopQueueAdapter` - No-operation queue for testing
16//! - **Work Types**: `HandleResolutionWork` - Work items for handle resolution
17//! - **Factory Functions**: Convenient functions for creating queue adapters
18//!
19//! # Examples
20//!
21//! ## Simple In-Memory Queue
22//!
23//! ```
24//! use quickdid::queue::{create_mpsc_queue, QueueAdapter};
25//!
26//! # async fn example() -> anyhow::Result<()> {
27//! let queue = create_mpsc_queue::<String>(100);
28//!
29//! queue.push("work-item".to_string()).await?;
30//! if let Some(item) = queue.pull().await {
31//! println!("Processing: {}", item);
32//! }
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! ## Persistent Queue with Work Shedding
38//!
39//! ```no_run
40//! use quickdid::queue::{create_sqlite_queue_with_max_size, HandleResolutionWork};
41//! use quickdid::sqlite_schema::create_sqlite_pool;
42//!
43//! # async fn example() -> anyhow::Result<()> {
44//! let pool = create_sqlite_pool("sqlite:./quickdid.db").await?;
45//! let queue = create_sqlite_queue_with_max_size::<HandleResolutionWork>(pool, 10000);
46//!
47//! let work = HandleResolutionWork::new("alice.bsky.social".to_string());
48//! queue.push(work).await?;
49//! # Ok(())
50//! # }
51//! ```
52
53// Internal modules
54mod adapter;
55mod error;
56mod factory;
57mod mpsc;
58mod noop;
59mod redis;
60mod sqlite;
61mod work;
62
63// Re-export core types
64pub use adapter::QueueAdapter;
65pub use error::{QueueError, Result};
66pub use work::{DedupKey, HandleResolutionWork};
67
68// Re-export implementations (with limited visibility)
69pub use mpsc::MpscQueueAdapter;
70pub use noop::NoopQueueAdapter;
71pub use redis::RedisQueueAdapter;
72pub use sqlite::SqliteQueueAdapter;
73
74// Re-export factory functions
75pub use factory::{
76 create_mpsc_queue, create_mpsc_queue_from_channel, create_noop_queue, create_redis_queue,
77 create_redis_queue_with_dedup, create_sqlite_queue, create_sqlite_queue_with_max_size,
78};