pub struct Attempt { /* private fields */ }Expand description
One run of a job, with the job’s ID, where the job came from, and how many times it has run.
A job’s handle may take &Attempt to ask the queue to release the job for later, delete
it, or fail it without retrying. Each request takes effect once handle returns, and a later
request replaces an earlier one:
use laravel::container::Inject;
use laravel::queue::{Attempt, job};
use laravel::time::ToSpan;
#[derive(laravel::queue::Queueable)]
pub struct ProcessPodcast {
pub podcast_id: i64,
}
#[job]
impl ProcessPodcast {
async fn handle(self, audio: Inject<AudioProcessor>, attempt: &Attempt) {
if audio.is_busy().await {
attempt.release(30.seconds());
}
}
}Implementations§
Source§impl Attempt
impl Attempt
Sourcepub fn connection(&self) -> &str
pub fn connection(&self) -> &str
The connection the job came from, such as database.
Sourcepub fn release(&self, delay: impl Into<ZonedDateTimeArithmetic>)
pub fn release(&self, delay: impl Into<ZonedDateTimeArithmetic>)
Put the job back on its queue to run again after delay.
The next run is another attempt, so it counts toward the job’s tries. The sync connection
doesn’t run released jobs again.
Sourcepub fn fail(&self, error: impl Into<Error>)
pub fn fail(&self, error: impl Into<Error>)
Fail the job for good without retrying it, and run its failed hook with error.
Sourcepub fn prepend_to_chain<Kind>(&self, jobs: impl IntoJobs<Kind>)
pub fn prepend_to_chain<Kind>(&self, jobs: impl IntoJobs<Kind>)
Run jobs next, in order, before the rest of the chain.
jobs is a job, a tuple of jobs, or an iterable of jobs of one type. A job that isn’t in a
chain starts one. The jobs join the chain only if this attempt succeeds or deletes the job.
If a job can’t be encoded, this calls fail with the encoding error.
Sourcepub fn append_to_chain<Kind>(&self, jobs: impl IntoJobs<Kind>)
pub fn append_to_chain<Kind>(&self, jobs: impl IntoJobs<Kind>)
Run jobs in order at the end of the chain, after every job already in the chain.
jobs is a job, a tuple of jobs, or an iterable of jobs of one type. A job that isn’t in a
chain starts one. The jobs join the chain only if this attempt succeeds or deletes the job.
If a job can’t be encoded, this calls fail with the encoding error.
Sourcepub const fn batch_id(&self) -> Option<BatchId>
pub const fn batch_id(&self) -> Option<BatchId>
The ID of the batch the job belongs to, or None when the job isn’t in a batch.
Sourcepub fn add_to_batch<Kind>(&self, jobs: impl IntoBatchJobs<Kind>)
pub fn add_to_batch<Kind>(&self, jobs: impl IntoBatchJobs<Kind>)
Add jobs to this job’s batch.
jobs is a job or chain, a tuple of jobs and chains, or an iterable of jobs or chains. The
new jobs join the batch only if this attempt succeeds or deletes the job, and they’re
dispatched to the same place as the batch’s other jobs. The batch doesn’t finish until the
new jobs have run.
If the job isn’t one of a batch’s jobs, or a job can’t be encoded, this calls
fail with the error.
Sourcepub fn cancel_batch(&self)
pub fn cancel_batch(&self)
Cancel this job’s batch once this attempt ends, however the attempt ends.
The batch skips its jobs that haven’t run yet, and its then callbacks never run. When the
job isn’t in a batch, this method does nothing.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Attempt
impl Forget for Attempt
impl Move for Attempt
impl RefUnwindSafe for Attemptwhere
Mutex<Effects>: RefUnwindSafe,
impl Send for Attempt
impl Sync for Attempt
impl Unpin for Attempt
impl UnsafeUnpin for Attemptwhere
&'static str: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Align4<u32>: UnsafeUnpin,
Align1<u8>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
PhantomData<Link>: UnsafeUnpin,
PhantomData<Chain>: UnsafeUnpin,
PhantomData<Uuid>: UnsafeUnpin,
impl UnwindSafe for Attempt
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
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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