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 with_locks(self, locks: LockManager) -> Self
pub fn with_locks(self, locks: LockManager) -> Self
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() -> Self
pub fn fake() -> Self
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: Job>(&self, job: J) -> Result<Option<String>>
pub async fn dispatch<J: Job>(&self, job: J) -> Result<Option<String>>
Queue job with its declared defaults.
Sourcepub async fn release_uniqueness(&self, key: &str) -> Result<bool>
pub async fn release_uniqueness(&self, key: &str) -> Result<bool>
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: Job>(&self, job: J) -> Result<PendingDispatch<'_>>
pub fn pending<J: Job>(&self, job: J) -> Result<PendingDispatch<'_>>
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: Job>(
&self,
queue: impl Into<String>,
job: J,
) -> Result<Option<String>>
pub async fn dispatch_on<J: Job>( &self, queue: impl Into<String>, job: J, ) -> Result<Option<String>>
Queue job on a named queue.
Sourcepub async fn dispatch_after<J: Job>(
&self,
delay: Duration,
job: J,
) -> Result<Option<String>>
pub async fn dispatch_after<J: Job>( &self, delay: Duration, job: J, ) -> Result<Option<String>>
Queue job, held back for delay.
Sourcepub async fn dispatch_now<J: Job>(
&self,
job: J,
container: Arc<Container>,
) -> Result<()>
pub async fn dispatch_now<J: Job>( &self, job: J, container: Arc<Container>, ) -> Result<()>
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: Job>(&self) -> Vec<QueuedJob>
pub fn pushed<J: Job>(&self) -> Vec<QueuedJob>
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: Job>(&self)
pub fn assert_pushed<J: Job>(&self)
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: Job>(&self, times: usize)
pub fn assert_pushed_times<J: Job>(&self, times: usize)
Panic unless exactly times J jobs were dispatched.
§Panics
If the count differs, or the manager is not faking.