Files
mytheclipse/crates/mytheclipse-queue
asepharyana 851c8c4ebb
CI / Rustfmt (push) Canceled after 0s
CI / Clippy (push) Canceled after 0s
CI / Test (workspace all features) (push) Canceled after 0s
CI / Test (workspace default features) (push) Canceled after 0s
CI / Test (mytheclipse / bg only) (push) Canceled after 0s
CI / Test (mytheclipse / compute only) (push) Canceled after 0s
CI / Test (mytheclipse / io only) (push) Canceled after 0s
CI / Test (mytheclipse / lifecycle only) (push) Canceled after 0s
CI / Test (mytheclipse / observability only) (push) Canceled after 0s
CI / Test (mytheclipse / resiliency only) (push) Canceled after 0s
CI / Test (mytheclipse / traffic only) (push) Canceled after 0s
CI / Test (mytheclipse-cache / l2-redis) (push) Canceled after 0s
CI / Test (mytheclipse-cache / l1-moka) (push) Canceled after 0s
CI / Test (mytheclipse-cache / default) (push) Canceled after 0s
CI / Test (mytheclipse-config / default) (push) Canceled after 0s
CI / Test (mytheclipse-crypto / default) (push) Canceled after 0s
CI / Test (mytheclipse-event / amqp) (push) Canceled after 0s
CI / Test (mytheclipse-event / nats) (push) Canceled after 0s
CI / Test (mytheclipse-event / default (mem)) (push) Canceled after 0s
CI / Test (mytheclipse-storage / gcs) (push) Canceled after 0s
CI / Test (mytheclipse-storage / s3) (push) Canceled after 0s
CI / Test (mytheclipse-storage / default (local)) (push) Canceled after 0s
CI / Run mytheclipse example (push) Canceled after 0s
CI / Docs check (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse) (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse-cache) (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse-config) (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse-crypto) (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse-event) (push) Canceled after 0s
CI / Cargo package dry-run (mytheclipse-storage) (push) Canceled after 0s
Release / Semantic Release (push) Canceled after 0s
feat: round-7 abstractions — BgJoiner, MiddlewarePipeline, RateLimitedQueue
2026-08-29 19:40:46 +07:00
..
2026-08-29 12:08:43 +00: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.

All backends share the same WorkerPool driver; swapping is a one-line change at construction time.

Features

Feature Default Backend Description
in-memory yes tokio::sync In-process queue, no external deps.
redis no redis crate (fred) Redis/Valkey list-based queue.
nats no async-nats NATS JetStream durable consumer.
postgres no tokio-postgres PostgreSQL SKIP LOCKED queue.

Usage

use mytheclipse_queue::{InMemoryQueue, WorkerPool, Job, JobHandler, JobFuture};

fn print_handler() -> impl JobHandler {
    struct PrintHandler;
    impl JobHandler for PrintHandler {
        fn handle(&self, job: Job) -> JobFuture {
            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", print_handler());

    Ok(())
}

Swap InMemoryQueue::new() for RedisQueue::connect("redis://127.0.0.1") (with the redis feature) or NatsQueue::connect("nats://127.0.0.1") (with the nats feature) to move to a distributed broker without touching handler code.