2026-08-29 16:04:50 +07:00
|
|
|
//! # mytheclipse-queue
|
|
|
|
|
//!
|
|
|
|
|
//! A unified job queue abstraction so your background work isn't locked to one
|
|
|
|
|
//! transport. Provides a single `Queue` trait, `Job` type, and `WorkerPool`
|
|
|
|
|
//! executor with configurable retry/backoff, concurrency, and a dead-letter
|
|
|
|
|
//! queue — behind pluggable backends:
|
|
|
|
|
//!
|
|
|
|
|
//! - **In-memory** (default) — `tokio::sync::mpsc` + task spawning, no external service.
|
|
|
|
|
//! - **Redis** (`redis`) — LIST-based queue with atomic moves.
|
|
|
|
|
//! - **NATS JetStream** (`nats`) — durable consumer with ACK/NACK.
|
|
|
|
|
//! - **PostgreSQL** (`postgres`) — `SKIP LOCKED` polling.
|
|
|
|
|
//!
|
|
|
|
|
//! ## Quick Start
|
|
|
|
|
//!
|
|
|
|
|
//! ```toml
|
|
|
|
|
//! [dependencies]
|
|
|
|
|
//! mytheclipse-queue = "0.2"
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! ```ignore
|
|
|
|
|
//! use mytheclipse_queue::{InMemoryQueue, WorkerPool, JobHandler, Job};
|
|
|
|
|
//! ...
|
|
|
|
|
//! let queue = InMemoryQueue::new();
|
|
|
|
|
//! queue.enqueue("email", b"hello".to_vec()).await?;
|
|
|
|
|
//!
|
|
|
|
|
//! fn make_handler() -> impl JobHandler {
|
|
|
|
|
//! struct PrintHandler;
|
|
|
|
|
//! impl JobHandler for PrintHandler {
|
|
|
|
|
//! fn handle(&self, job: Job) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), mytheclipse_queue::JobError>> + Send>> {
|
|
|
|
|
//! Box::pin(async move {
|
|
|
|
|
//! println!("payload: {:?}", job.payload);
|
|
|
|
|
//! Ok(())
|
|
|
|
|
//! })
|
|
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! PrintHandler
|
|
|
|
|
//! }
|
|
|
|
|
//!
|
|
|
|
|
//! # #[tokio::main]
|
|
|
|
|
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
|
//! let queue = InMemoryQueue::new();
|
|
|
|
|
//! queue.enqueue("email", b"hello".to_vec()).await?;
|
|
|
|
|
//!
|
|
|
|
|
//! let pool = WorkerPool::new(queue, 4);
|
|
|
|
|
//! pool.start("email", make_handler());
|
|
|
|
|
//! # Ok(())
|
|
|
|
|
//! # }
|
|
|
|
|
//! ```
|
|
|
|
|
|
|
|
|
|
pub mod error;
|
2026-08-29 17:05:37 +07:00
|
|
|
pub mod job;
|
2026-08-29 16:04:50 +07:00
|
|
|
#[cfg(feature = "in-memory")]
|
|
|
|
|
pub mod in_memory;
|
2026-08-29 17:05:37 +07:00
|
|
|
pub mod traits;
|
|
|
|
|
pub mod worker;
|
|
|
|
|
|
2026-08-29 18:19:42 +07:00
|
|
|
#[cfg(feature = "in-memory")]
|
|
|
|
|
pub mod batch;
|
|
|
|
|
#[cfg(feature = "in-memory")]
|
|
|
|
|
pub mod pipeline;
|
|
|
|
|
|
2026-08-29 16:04:50 +07:00
|
|
|
#[cfg(feature = "in-memory")]
|
|
|
|
|
pub use in_memory::InMemoryQueue;
|
|
|
|
|
|
|
|
|
|
pub use traits::Queue;
|
|
|
|
|
pub use job::{Job, JobId};
|
|
|
|
|
pub use worker::{WorkerPool, WorkerConfig, JobHandler, JobFuture};
|
|
|
|
|
pub use error::{QueueError, JobError};
|
2026-08-29 17:05:37 +07:00
|
|
|
|
|
|
|
|
#[cfg(feature = "in-memory")]
|
2026-08-29 18:19:42 +07:00
|
|
|
pub use batch::{BatchConfig, BatchJobHandler, BatchProcessor, BatchFlush};
|
2026-08-29 17:05:37 +07:00
|
|
|
#[cfg(feature = "in-memory")]
|
|
|
|
|
pub use pipeline::{StageRunner, Stage, StageError};
|