Skip to main content

Queue

Trait Queue 

Source
pub trait Queue:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn push<'a>(&'a self, job: QueuedJob) -> BoxFuture<'a, Result<String>>;
    fn reserve<'a>(
        &'a self,
        queue: &'a str,
    ) -> BoxFuture<'a, Result<Option<QueuedJob>>>;
    fn acknowledge<'a>(
        &'a self,
        job: &'a QueuedJob,
    ) -> BoxFuture<'a, Result<()>>;
    fn release<'a>(
        &'a self,
        job: &'a QueuedJob,
        delay: Duration,
    ) -> BoxFuture<'a, Result<()>>;
    fn fail<'a>(
        &'a self,
        job: &'a QueuedJob,
        error: &'a str,
    ) -> BoxFuture<'a, Result<()>>;
    fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>;
    fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>;
}
Expand description

A queue backend.

The contract is deliberately “reserve, then acknowledge” rather than “pop”: a worker that crashes mid-job must not lose it. A reserved job stays in the store, invisible to other workers, until it is acknowledged, released or its reservation times out.

Required Methods§

Source

fn name(&self) -> &str

A label for diagnostics — "database", "memory", "sync".

Source

fn push<'a>(&'a self, job: QueuedJob) -> BoxFuture<'a, Result<String>>

Enqueue a job.

Source

fn reserve<'a>( &'a self, queue: &'a str, ) -> BoxFuture<'a, Result<Option<QueuedJob>>>

Reserve the next available job on queue, or None if there is none.

Source

fn acknowledge<'a>(&'a self, job: &'a QueuedJob) -> BoxFuture<'a, Result<()>>

Remove a finished job.

Source

fn release<'a>( &'a self, job: &'a QueuedJob, delay: Duration, ) -> BoxFuture<'a, Result<()>>

Return a job to the queue for another attempt, available after delay.

Source

fn fail<'a>( &'a self, job: &'a QueuedJob, error: &'a str, ) -> BoxFuture<'a, Result<()>>

Move a job to the failed store after its last attempt.

Source

fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>

How many jobs are waiting on queue.

Source

fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>

Discard everything on queue. Returns how many were removed.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§