pub struct Queue { /* private fields */ }Expand description
Dispatches jobs and wakes the workers of this process.
Implementations§
Source§impl Queue
impl Queue
Sourcepub async fn stats(&self) -> Result<QueueStats>
pub async fn stats(&self) -> Result<QueueStats>
Counts for monitoring (the dashboard shows them).
Sourcepub async fn recent_batches(&self, limit: u32) -> Result<Vec<BatchStatus>>
pub async fn recent_batches(&self, limit: u32) -> Result<Vec<BatchStatus>>
The most recent batches, newest first.
Source§impl Queue
impl Queue
Sourcepub async fn dispatch<J: Job>(&self, job: J) -> Result<i64>
pub async fn dispatch<J: Job>(&self, job: J) -> Result<i64>
Queues a job to run as soon as a worker is free; returns its id.
Sourcepub async fn dispatch_after<J: Job>(
&self,
job: J,
delay: Duration,
) -> Result<i64>
pub async fn dispatch_after<J: Job>( &self, job: J, delay: Duration, ) -> Result<i64>
Queues a job to run after delay; returns its id.
Sourcepub async fn dispatch_on<J: Job>(&self, queue: &str, job: J) -> Result<i64>
pub async fn dispatch_on<J: Job>(&self, queue: &str, job: J) -> Result<i64>
Queues a job on queue instead of its Job::QUEUE.
Sourcepub async fn dispatch_in<J: Job>(
&self,
tx: &mut Transaction,
job: J,
) -> Result<i64>
pub async fn dispatch_in<J: Job>( &self, tx: &mut Transaction, job: J, ) -> Result<i64>
Queues a job inside tx, so it only exists if the transaction
commits; workers pick it up within a second of the commit. Use it
instead of dispatch while a transaction is open: on SQLite, which
writes one transaction at a time, dispatch would wait for tx.
let mut tx = state.db.begin().await?;
let order_id: i64 = renox::db::sql("INSERT INTO orders (total) VALUES (?) RETURNING id")
.bind(75_000)
.scalar(&mut tx)
.await?;
state.queue.dispatch_in(&mut tx, SendReceipt { order_id }).await?;
tx.commit().await?; // no order, no receiptSourcepub fn chain(&self) -> Chain
pub fn chain(&self) -> Chain
Jobs that run one after another: the next is queued when the one
before succeeds, and a job that fails for good stops the chain
(queue:retry resumes it).
Sourcepub fn batch(&self, name: &str) -> Batch
pub fn batch(&self, name: &str) -> Batch
Jobs that run side by side, tracked together; see Batch.
Sourcepub async fn batch_status(&self, id: i64) -> Result<Option<BatchStatus>>
pub async fn batch_status(&self, id: i64) -> Result<Option<BatchStatus>>
How a batch is doing; None if there’s no such batch.
Sourcepub async fn cancel_batch(&self, id: i64) -> Result<bool>
pub async fn cancel_batch(&self, id: i64) -> Result<bool>
Cancels a batch: its jobs that haven’t run are skipped.
Sourcepub async fn retry(&self, id: i64) -> Result<bool>
pub async fn retry(&self, id: i64) -> Result<bool>
Puts the failed job id back on its queue with fresh attempts (and
its chain and batch); returns whether there was such a job.
Sourcepub async fn retry_all(&self) -> Result<u64>
pub async fn retry_all(&self) -> Result<u64>
Puts every failed job back on its queue; returns how many.
Sourcepub async fn forget_failed(&self, id: i64) -> Result<bool>
pub async fn forget_failed(&self, id: i64) -> Result<bool>
Deletes one failed job; returns whether it existed.
Sourcepub async fn prune_failed(&self, age: Duration) -> Result<u64>
pub async fn prune_failed(&self, age: Duration) -> Result<u64>
Deletes failed jobs older than age; returns how many.
Sourcepub async fn prune_batches(&self, age: Duration) -> Result<u64>
pub async fn prune_batches(&self, age: Duration) -> Result<u64>
Deletes batches that finished (or were cancelled) more than age ago.
Sourcepub async fn flush_failed(&self) -> Result<u64>
pub async fn flush_failed(&self) -> Result<u64>
Deletes failed jobs.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Queue
impl !UnwindSafe for Queue
impl Freeze for Queue
impl Send for Queue
impl Sync for Queue
impl Unpin for Queue
impl UnsafeUnpin for Queue
Blanket Implementations§
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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