Skip to main content

Queue

Trait Queue 

Source
pub trait Queue: Send + Sync {
    // Required methods
    fn enqueue<'life0, 'life1, 'async_trait>(
        &'life0 self,
        topic: &'life1 str,
        payload: Vec<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn dequeue<'life0, 'life1, 'async_trait>(
        &'life0 self,
        topic: &'life1 str,
        timeout: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Job>, QueueError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn ack<'life0, 'life1, 'async_trait>(
        &'life0 self,
        job: &'life1 Job,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn nack<'life0, 'life1, 'async_trait>(
        &'life0 self,
        job: &'life1 Job,
        requeue: bool,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn dlq_move<'life0, 'life1, 'async_trait>(
        &'life0 self,
        topic: &'life1 str,
        job: Job,
    ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn len<'life0, 'life1, 'async_trait>(
        &'life0 self,
        topic: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<u64, QueueError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn is_empty<'life0, 'life1, 'async_trait>(
        &'life0 self,
        topic: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, QueueError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

A handle to a single unit of queued work.

Job carries the raw payload (arbitrary bytes — caller decides encoding) plus metadata the queue implementation fills in (ID, enqueue time, retry count). ack/nack are only valid on backends that support explicit acknowledgment (NATS, Redis BLPOP-with-confirm). For in-memory and Postgres backends, the worker auto-acknowledges on Ok and auto-requeues on Err.

A trait for enqueueing and dequeueing jobs.

Implementations must be Send + Sync. Each backend provides its own factory (e.g. InMemoryQueue::new(), RedisQueue::connect(url)).

Required Methods§

Source

fn enqueue<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, payload: Vec<u8>, ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Enqueues payload onto topic.

Source

fn dequeue<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, timeout: Duration, ) -> Pin<Box<dyn Future<Output = Result<Option<Job>, QueueError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Dequeues the next job from topic, waiting up to timeout.

Returns None on timeout when the queue is empty and no job arrives within the window.

Source

fn ack<'life0, 'life1, 'async_trait>( &'life0 self, job: &'life1 Job, ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Acknowledges a job as successfully processed.

Source

fn nack<'life0, 'life1, 'async_trait>( &'life0 self, job: &'life1 Job, requeue: bool, ) -> Pin<Box<dyn Future<Output = Result<(), JobError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Negative-acknowledges a job. If requeue is true the job goes back onto the queue; if false it moves to the dead-letter queue (if configured).

Source

fn dlq_move<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, job: Job, ) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Moves a job to the dead-letter queue for topic.

Source

fn len<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, QueueError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Number of messages currently waiting in topic.

Provided Methods§

Source

fn is_empty<'life0, 'life1, 'async_trait>( &'life0 self, topic: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, QueueError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Whether the queue is empty.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§