Skip to main content

Queue

Trait Queue 

Source
pub trait Queue:
    Send
    + Sync
    + 'static {
    // Required methods
    fn enqueue(
        &self,
        queue: &str,
        payloads: Vec<Value>,
    ) -> impl Future<Output = Result<(), QueueError>> + Send;
    fn enqueue_ordered(
        &self,
        queue: &str,
        jobs: Vec<(String, Value)>,
    ) -> impl Future<Output = Result<(), QueueError>> + Send;
    fn claim(
        &self,
        queue: &str,
        limit: usize,
        lease: Duration,
    ) -> impl Future<Output = Result<Vec<Job>, QueueError>> + Send;
    fn complete(
        &self,
        id: &str,
    ) -> impl Future<Output = Result<(), QueueError>> + Send;
    fn retry(
        &self,
        id: &str,
        delay: Duration,
        error: &str,
    ) -> impl Future<Output = Result<(), QueueError>> + Send;
    fn fail(
        &self,
        id: &str,
        error: &str,
    ) -> impl Future<Output = Result<(), QueueError>> + Send;
    fn next_due(
        &self,
        queue: &str,
    ) -> impl Future<Output = Result<Option<Duration>, QueueError>> + Send;
}
Expand description

A queue backend.

One backend holds any number of named queues, each claimed separately, so that deliveries and incoming activities can share a table without one starving the other.

Required Methods§

Source

fn enqueue( &self, queue: &str, payloads: Vec<Value>, ) -> impl Future<Output = Result<(), QueueError>> + Send

Queue payloads in queue, due now.

Source

fn enqueue_ordered( &self, queue: &str, jobs: Vec<(String, Value)>, ) -> impl Future<Output = Result<(), QueueError>> + Send

Queue jobs in queue, due now, each with its ordering key. A job is not claimed while another with the same key, queued before it in any queue, is still waiting, claimed or due to be retried; once that one is complete or failed, the next is. Jobs with different keys, and jobs with none, are claimed as they come due.

Source

fn claim( &self, queue: &str, limit: usize, lease: Duration, ) -> impl Future<Output = Result<Vec<Job>, QueueError>> + Send

Claim up to limit due jobs from queue for lease. None of them is claimed again until the lease lapses.

Source

fn complete( &self, id: &str, ) -> impl Future<Output = Result<(), QueueError>> + Send

A job is done; it will not be seen again.

Source

fn retry( &self, id: &str, delay: Duration, error: &str, ) -> impl Future<Output = Result<(), QueueError>> + Send

A job is to be tried again after delay.

Source

fn fail( &self, id: &str, error: &str, ) -> impl Future<Output = Result<(), QueueError>> + Send

A job will not be tried again.

Source

fn next_due( &self, queue: &str, ) -> impl Future<Output = Result<Option<Duration>, QueueError>> + Send

How long until the next job in queue is due, if one is waiting: how long a worker with nothing to do may sleep.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§