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 it waits in the hold queue for its delay,
exactly as a retry does, so different delays never block each other. Use
Producer::defer when the job must come back ahead of the backlog.
On RabbitMQ this needs the queue to have been declared through the same backend
(which Producer::new does and Producer::new_undeclared does not), and the
delay is capped at about 24.8 days; see the backend’s docs.
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 returns at priority 0, behind
the backlog; this one returns at the top. Both wait in a hold per delay, so
equal delays drain strictly in order and different delays never block each
other.