pub struct Producer<Q: QueueSet, B: Backend> { /* private fields */ }Expand description
Type-safe publisher. Q pins the producer to one queue set so a job from a
different application cannot be enqueued by accident.
Implementations§
Source§impl<Q: QueueSet, B: Backend> Producer<Q, B>
impl<Q: QueueSet, B: Backend> Producer<Q, B>
Sourcepub async fn new(backend: Arc<B>) -> Result<Self>
pub async fn new(backend: Arc<B>) -> Result<Self>
Create a producer and declare all queues in Q.
Sourcepub fn new_undeclared(backend: Arc<B>) -> Self
pub fn new_undeclared(backend: Arc<B>) -> Self
Create a producer without declaring queues (they must already exist).
Sourcepub async fn enqueue<J: Job<Queue = Q>>(&self, job: &J) -> Result<Uuid>
pub async fn enqueue<J: Job<Queue = Q>>(&self, job: &J) -> Result<Uuid>
Publish job to its statically-known queue. Returns the job id.
Sourcepub async fn enqueue_after<J: Job<Queue = Q>>(
&self,
job: &J,
delay: Duration,
) -> Result<Uuid>
pub async fn enqueue_after<J: Job<Queue = Q>>( &self, job: &J, delay: Duration, ) -> Result<Uuid>
Publish job, to become visible after delay.
The plain delay: the job waits, then joins the back of the queue like any other
message (priority 0). On RabbitMQ every delayed publish of a queue shares one
wait queue, so a message with a long delay sitting at its head holds up shorter
ones behind it. Use Producer::defer when the job must come back ahead of
the backlog, or when many different delays are in play.
Sourcepub async fn defer<J: Job<Queue = Q>>(
&self,
job: &J,
delay: Duration,
) -> Result<Uuid>
pub async fn defer<J: Job<Queue = Q>>( &self, job: &J, delay: Duration, ) -> Result<Uuid>
Publish job into a hold that releases it after delay, at the front of the
queue. Returns the job id.
The envelope is a first-attempt one (attempt = 1, deferrals = 0) carrying
the highest priority its queue supports
(crate::QueueConfig::max_priority, 0 when the queue is not a priority
queue), so when the delay is up it runs before everything that was enqueued
normally in the meantime. The producer-side twin of a handler returning
crate::JobError::Deferred.
Contrast with Producer::enqueue_after: that shares one wait queue per queue
(head-of-line blocking between different delays on RabbitMQ) and returns at
priority 0; this one is held per delay (equal delays drain strictly in order)
and returns at the top.