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§
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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).
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".