Skip to main content

Queue

Trait Queue 

Source
pub trait Queue:
    Send
    + Sync
    + 'static {
    // Required methods
    fn driver(&self) -> &'static str;
    fn push(&self, job: QueuedJob) -> BoxFuture<'_, Result<String>>;
    fn pop<'a>(
        &'a self,
        queue: &'a str,
    ) -> BoxFuture<'a, Result<Option<ReservedJob>>>;
    fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>;
    fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>;
    fn release<'a>(
        &'a self,
        job: &'a ReservedJob,
        delay: Duration,
    ) -> BoxFuture<'a, Result<()>>;
    fn fail<'a>(
        &'a self,
        job: &'a ReservedJob,
        error: &'a str,
    ) -> BoxFuture<'a, Result<()>>;
    fn failed_jobs(&self) -> BoxFuture<'_, Result<Vec<FailedJob>>>;
    fn clear<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>;

    // Provided methods
    fn push_on<'a>(
        &'a self,
        queue: &'a str,
        job: QueuedJob,
    ) -> BoxFuture<'a, Result<String>> { ... }
    fn later<'a>(
        &'a self,
        delay: Duration,
        job: QueuedJob,
    ) -> BoxFuture<'a, Result<String>> { ... }
}
Expand description

A queue backend.

Required Methods§

Source

fn driver(&self) -> &'static str

The driver’s name. It appears in queue.* events and error messages, which is how Telescope shows which backend handled a job.

Source

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

Store a job. Returns the driver’s identifier for it.

The envelope carries its own queue and delay, so this one primitive is all a driver has to implement.

Source

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

Reserve the next available job, or None when there is nothing ready.

A delayed job whose time has not come is not “available”; neither is one another worker already holds. Reserving must be atomic across workers — see the database driver for how that is done and why.

Source

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

How many jobs are waiting on a queue, including delayed ones.

Source

fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>

Finish with a reserved job: it succeeded and is gone.

Source

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

Put a reserved job back, available again after delay.

The attempt count is kept, which is what makes a retry a retry rather than a fresh job that will fail forever.

Source

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

Move a reserved job to the dead-letter store with the error that killed it. It must no longer be on the queue afterwards.

Source

fn failed_jobs(&self) -> BoxFuture<'_, Result<Vec<FailedJob>>>

Everything in the dead-letter store, oldest first.

Source

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

Throw away every job waiting on a queue. Returns how many went.

Provided Methods§

Source

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

Store a job on a named queue, whatever the job itself asked for.

Source

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

Store a job that only becomes visible to a worker after delay.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§