Skip to main content

QueueManager

Struct QueueManager 

Source
pub struct QueueManager { /* private fields */ }
Expand description

Dispatches jobs onto the configured queue.

The accessor behind the Queue facade.

Implementations§

Source§

impl QueueManager

Source

pub fn new(queue: Arc<dyn Queue>, registry: Arc<JobRegistry>) -> QueueManager

Dispatch onto queue.

Source

pub fn with_locks(self, locks: LockManager) -> QueueManager

Enforce Job::unique_id with locks taken from locks.

Without this a job that declares a unique_id is dispatched normally. That is the deliberate choice: quietly not deduplicating is a bug you find in production, and quietly deduplicating against a per-process cache is the same bug wearing a hat. Wiring it is one line, and Rainier::boot does it.

A warning is logged the first time a unique job is dispatched without one, so the gap is visible rather than silent.

Source

pub fn fake() -> QueueManager

A manager that records dispatches instead of performing them.

The test-double form of Queue::fake(): a test can assert that an action queued the right job without a worker ever running it.

Source

pub fn is_faking(&self) -> bool

Whether this manager is recording instead of dispatching.

Source

pub fn queue(&self) -> &Arc<dyn Queue> ⓘ

The underlying queue.

Source

pub fn registry(&self) -> &Arc<JobRegistry> ⓘ

The job registry.

Source

pub async fn dispatch<J>(&self, job: J) -> Result<Option<String>, Error>
where J: Job,

Queue job with its declared defaults.

Source

pub async fn release_uniqueness(&self, key: &str) -> Result<bool, Error>

Release the uniqueness lock for a job that has finished.

Called by the worker. Releasing on completion rather than on dispatch is what makes the guarantee “one pending or running at a time” rather than “one every UNIQUE_FOR”.

A force_release rather than a token-checked one, and this is the one place that is right: the acquirer was the dispatching process, which is long gone and never handed its token over. Nothing else takes this key — dispatch is its only other user — and the job it belonged to is over.

Source

pub fn pending<J>(&self, job: J) -> Result<PendingDispatch<'_>, Error>
where J: Job,

Start a dispatch that can be configured before sending.

ⓘ
queue.pending(SendInvoice { id })?.on_queue("billing").delay(TEN_MINUTES).send().await?;
Source

pub async fn dispatch_on<J>( &self, queue: impl Into<String>, job: J, ) -> Result<Option<String>, Error>
where J: Job,

Queue job on a named queue.

Source

pub async fn dispatch_after<J>( &self, delay: Duration, job: J, ) -> Result<Option<String>, Error>
where J: Job,

Queue job, held back for delay.

Source

pub async fn dispatch_now<J>( &self, job: J, container: Arc<Container>, ) -> Result<(), Error>
where J: Job,

Run job right now instead of queueing it.

Bypasses the queue entirely, so failures surface to the caller. For a job the caller genuinely needs to have finished.

Source

pub fn pushed<J>(&self) -> Vec<QueuedJob>
where J: Job,

Every recorded dispatch of J. Always empty unless faking.

Source

pub fn all_pushed(&self) -> Vec<QueuedJob>

Every recorded dispatch, of any type.

Source

pub fn assert_pushed<J>(&self)
where J: Job,

Panic unless a J was dispatched.

§Panics

If none was, or the manager is not faking — which would otherwise make every assertion pass vacuously.

Source

pub fn assert_pushed_times<J>(&self, times: usize)
where J: Job,

Panic unless exactly times J jobs were dispatched.

§Panics

If the count differs, or the manager is not faking.

Source

pub fn assert_not_pushed<J>(&self)
where J: Job,

Panic if any J was dispatched.

§Panics

If one was, or the manager is not faking.

Source

pub fn assert_pushed_on<J>(&self, queue: &str)
where J: Job,

Panic unless a J was dispatched onto queue.

§Panics

If none was, or the manager is not faking.

Trait Implementations§

Source§

impl Debug for QueueManager

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Actor for T
where T: Send + Sync + 'static,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Event for T
where T: Send + Sync + 'static,

Source§

fn event_name() -> &'static str
where Self: Sized,

A human-readable name, used by wildcard listeners and log output. Always the Rust type path; see the trait docs.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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