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§
Sourcefn driver(&self) -> &'static str
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.
Sourcefn push(&self, job: QueuedJob) -> BoxFuture<'_, Result<String>>
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.
Sourcefn pop<'a>(
&'a self,
queue: &'a str,
) -> BoxFuture<'a, Result<Option<ReservedJob>>>
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.
Sourcefn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
fn size<'a>(&'a self, queue: &'a str) -> BoxFuture<'a, Result<u64>>
How many jobs are waiting on a queue, including delayed ones.
Sourcefn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>
fn delete<'a>(&'a self, job: &'a ReservedJob) -> BoxFuture<'a, Result<()>>
Finish with a reserved job: it succeeded and is gone.
Sourcefn release<'a>(
&'a self,
job: &'a ReservedJob,
delay: Duration,
) -> BoxFuture<'a, Result<()>>
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.
Sourcefn fail<'a>(
&'a self,
job: &'a ReservedJob,
error: &'a str,
) -> BoxFuture<'a, Result<()>>
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.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".