pub struct QueueManager { /* private fields */ }Expand description
Dispatches jobs onto the configured queue.
The accessor behind the Queue facade.
Implementations§
Source§impl QueueManager
impl QueueManager
Sourcepub fn new(queue: Arc<dyn Queue>, registry: Arc<JobRegistry>) -> QueueManager
pub fn new(queue: Arc<dyn Queue>, registry: Arc<JobRegistry>) -> QueueManager
Dispatch onto queue.
Sourcepub fn with_locks(self, locks: LockManager) -> QueueManager
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.
Sourcepub fn fake() -> QueueManager
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.
Sourcepub fn registry(&self) -> &Arc<JobRegistry> ⓘ
pub fn registry(&self) -> &Arc<JobRegistry> ⓘ
The job registry.
Sourcepub async fn dispatch<J>(&self, job: J) -> Result<Option<String>, Error>where
J: Job,
pub async fn dispatch<J>(&self, job: J) -> Result<Option<String>, Error>where
J: Job,
Queue job with its declared defaults.
Sourcepub async fn release_uniqueness(&self, key: &str) -> Result<bool, Error>
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.
Sourcepub fn pending<J>(&self, job: J) -> Result<PendingDispatch<'_>, Error>where
J: Job,
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?;Sourcepub async fn dispatch_on<J>(
&self,
queue: impl Into<String>,
job: J,
) -> Result<Option<String>, Error>where
J: Job,
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.
Sourcepub async fn dispatch_after<J>(
&self,
delay: Duration,
job: J,
) -> Result<Option<String>, Error>where
J: Job,
pub async fn dispatch_after<J>(
&self,
delay: Duration,
job: J,
) -> Result<Option<String>, Error>where
J: Job,
Queue job, held back for delay.
Sourcepub async fn dispatch_now<J>(
&self,
job: J,
container: Arc<Container>,
) -> Result<(), Error>where
J: Job,
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.
Sourcepub fn pushed<J>(&self) -> Vec<QueuedJob>where
J: Job,
pub fn pushed<J>(&self) -> Vec<QueuedJob>where
J: Job,
Every recorded dispatch of J. Always empty unless faking.
Sourcepub fn all_pushed(&self) -> Vec<QueuedJob>
pub fn all_pushed(&self) -> Vec<QueuedJob>
Every recorded dispatch, of any type.
Sourcepub fn assert_pushed<J>(&self)where
J: Job,
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.
Sourcepub fn assert_pushed_times<J>(&self, times: usize)where
J: Job,
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.
Sourcepub fn assert_not_pushed<J>(&self)where
J: Job,
pub fn assert_not_pushed<J>(&self)where
J: Job,
Sourcepub fn assert_pushed_on<J>(&self, queue: &str)where
J: Job,
pub fn assert_pushed_on<J>(&self, queue: &str)where
J: Job,
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for QueueManager
impl !RefUnwindSafe for QueueManager
impl !UnwindSafe for QueueManager
impl Send for QueueManager
impl Sync for QueueManager
impl Unpin for QueueManager
impl UnsafeUnpin for QueueManager
Blanket Implementations§
impl<T> Actor for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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