Skip to main content

Attempt

Struct Attempt 

Source
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

Source

pub const fn id(&self) -> JobId

The job’s ID, assigned when it was dispatched.

Source

pub const fn name(&self) -> &'static str

The job’s name, as #[job] registered the job.

Source

pub fn connection(&self) -> &str

The connection the job came from, such as database.

Source

pub fn queue(&self) -> &str

The queue the job came from, such as default.

Source

pub const fn number(&self) -> u32

The number of this run, starting at 1.

Source

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.

Source

pub fn delete(&self)

Remove the job from its queue without running it again or failing it.

Source

pub fn fail(&self, error: impl Into<Error>)

Fail the job for good without retrying it, and run its failed hook with error.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for Attempt

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Attempt

§

impl Forget for Attempt

§

impl Move for Attempt

§

impl RefUnwindSafe for Attempt
where Mutex<Effects>: RefUnwindSafe,

§

impl Send for Attempt
where &'static str: Send, RawVecInner: Send, Mutex<Effects>: Send,

§

impl Sync for Attempt
where RawVecInner: Sync, Mutex<Effects>: Sync,

§

impl Unpin for Attempt
where &'static str: Unpin, *const u8 is !null: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, Arc<Inner>: Unpin, Arc<ModelRows>: Unpin, Box<BatchSpec>: Unpin,

§

impl UnsafeUnpin for Attempt
where &'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
where &'static str: UnwindSafe, RawVecInner: UnwindSafe, Mutex<Effects>: UnwindSafe,

Blanket Implementations§

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Fake for T

Source§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

Source§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> FillValue<Option<T>> for T
where T: Send + 'static,

Source§

async fn fill(self) -> Result<Option<T>, Error>

Resolves the column’s value. Read more
Source§

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

Source§

async fn fill(self) -> Result<T, Error>

Resolves the column’s value. Read more
Source§

impl<K> ForeignKey<K> for K

Source§

fn key(&self) -> Option<&K>

Returns the key, or None when the field holds no key.
Source§

fn __from_key(key: K) -> K

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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, N> NotifiedBy<T> for N
where T: Notification<N>,

Source§

fn __routes(&self) -> Vec<Route>

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<T, V> UpdateValue<T> for V
where V: FillValue<T>,

Source§

fn __update<M, U>(self, column: Column<M, T>, update: U) -> U
where M: Model, U: Updates<M>, T: IntoExpr + Clone + Send + Sync + 'static,

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