Skip to main content

Producer

Struct Producer 

Source
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>

Source

pub async fn new(backend: Arc<B>) -> Result<Self>

Create a producer and declare all queues in Q.

Source

pub fn new_undeclared(backend: Arc<B>) -> Self

Create a producer without declaring queues (they must already exist).

Source

pub async fn enqueue<J: Job<Queue = Q>>(&self, job: &J) -> Result<Uuid>

Publish job to its statically-known queue. Returns the job id.

Source

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.

Source

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.

Source

pub fn backend(&self) -> &Arc<B>

The backend this producer publishes through.

Trait Implementations§

Source§

impl<Q: QueueSet, B: Backend> Clone for Producer<Q, B>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Q, B> Freeze for Producer<Q, B>
where Arc<B>: Freeze, PhantomData<fn(Q)>: Freeze,

§

impl<Q, B> RefUnwindSafe for Producer<Q, B>

§

impl<Q, B> Send for Producer<Q, B>
where Arc<B>: Send, PhantomData<fn(Q)>: Send,

§

impl<Q, B> Sync for Producer<Q, B>
where Arc<B>: Sync, PhantomData<fn(Q)>: Sync,

§

impl<Q, B> Unpin for Producer<Q, B>
where Arc<B>: Unpin, PhantomData<fn(Q)>: Unpin,

§

impl<Q, B> UnsafeUnpin for Producer<Q, B>

§

impl<Q, B> UnwindSafe for Producer<Q, B>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more