pub struct PendingBatch { /* private fields */ }Expand description
A batch of jobs on its way to the queue.
Await the batch to dispatch every job at once. Awaiting returns the batch’s BatchId. The
errors and panics of awaiting are listed on queue::batch.
The jobs run side by side, on as many workers as pick them up. Once every job has run, the
worker that ran the last job calls the batch’s then callbacks if every job
succeeded, and its finally callbacks in every case. When the first job
fails for good, its worker calls the catch callbacks with the job’s error and
cancels the batch, unless the batch allows failures. Inside a
database transaction, the batch waits for the transaction to commit, as a
dispatch does.
use laravel::queue;
let batch_id = queue::batch([
ImportCsv { import_id, chunk: 1 },
ImportCsv { import_id, chunk: 2 },
ImportCsv { import_id, chunk: 3 },
])
.name("Import CSV")
.then(ImportFinished { import_id })
.catch(ImportFinished { import_id })
.await?;Implementations§
Source§impl PendingBatch
impl PendingBatch
Sourcepub fn name(self, name: impl Into<String>) -> PendingBatch
pub fn name(self, name: impl Into<String>) -> PendingBatch
Give the batch a name, which Batch::name returns.
Sourcepub fn then(self, callback: impl Then) -> PendingBatch
pub fn then(self, callback: impl Then) -> PendingBatch
Call callback’s then method once every job of the batch has succeeded.
A cancelled batch never calls the callback. Each call adds another callback.
Sourcepub fn catch(self, callback: impl Catch) -> PendingBatch
pub fn catch(self, callback: impl Catch) -> PendingBatch
Call callback’s catch method with the error when the first of the batch’s jobs fails
for good.
Each call adds another callback.
Sourcepub fn finally(self, callback: impl Finally) -> PendingBatch
pub fn finally(self, callback: impl Finally) -> PendingBatch
Call callback’s finally method once every job of the batch has run.
The callback runs whether each job succeeded, failed, or was skipped because the batch was
cancelled. Each call adds another callback. A retried job that adds jobs to a finished batch,
or continues its chain, makes the batch unfinished again. Once those new jobs have run, the
worker calls finally again.
Sourcepub fn allow_failures(self) -> PendingBatch
pub fn allow_failures(self) -> PendingBatch
Keep the batch running when one of its jobs fails for good, rather than cancelling it.
Sourcepub fn on_connection(self, connection: impl Into<String>) -> PendingBatch
pub fn on_connection(self, connection: impl Into<String>) -> PendingBatch
Push every job of the batch to this connection rather than the default one.
Sourcepub fn on_queue(self, queue: impl Into<String>) -> PendingBatch
pub fn on_queue(self, queue: impl Into<String>) -> PendingBatch
Push every job of the batch to this queue, rather than the queue that each job’s options or connection choose.
Trait Implementations§
Source§impl Debug for PendingBatch
impl Debug for PendingBatch
Source§impl IntoFuture for PendingBatch
impl IntoFuture for PendingBatch
Source§type IntoFuture = Pin<Box<dyn Future<Output = Result<BatchId, Error>> + Send>>
type IntoFuture = Pin<Box<dyn Future<Output = Result<BatchId, Error>> + Send>>
Source§fn into_future(self) -> <PendingBatch as IntoFuture>::IntoFuture
fn into_future(self) -> <PendingBatch as IntoFuture>::IntoFuture
impl IntoJobs for PendingBatch
A batch can be a step of a chain, and the chain continues once every job of the batch has run.
Auto Trait Implementations§
impl !RefUnwindSafe for PendingBatch
impl !UnwindSafe for PendingBatch
impl Forget for PendingBatch
impl Freeze for PendingBatchwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Chain>: Freeze,
PhantomData<EncodedCallback>: Freeze,
PhantomData<Link>: Freeze,
*const ArcInner<Inner> is !null: Freeze,
PhantomData<ArcInner<Inner>>: Freeze,
&'static Location<'static>: Freeze,
impl Move for PendingBatch
impl Send for PendingBatch
impl Sync for PendingBatch
impl Unpin for PendingBatch
impl UnsafeUnpin for PendingBatchwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Chain>: UnsafeUnpin,
PhantomData<EncodedCallback>: UnsafeUnpin,
PhantomData<Link>: UnsafeUnpin,
*const ArcInner<Inner> is !null: UnsafeUnpin,
PhantomData<ArcInner<Inner>>: UnsafeUnpin,
&'static Location<'static>: UnsafeUnpin,
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