W3cubDocs

/Laravel 8

Batch

class Batch implements Arrayable, JsonSerializable (View source)

Properties

protected Factory $queue The queue factory implementation.
protected BatchRepository $repository The repository implementation.
string $id The batch ID.
string $name The batch name.
int $totalJobs The total number of jobs that belong to the batch.
int $pendingJobs The total number of jobs that are still pending.
int $failedJobs The total number of jobs that have failed.
array $failedJobIds The IDs of the jobs that have failed.
array $options The batch options.
CarbonImmutable $createdAt The date indicating when the batch was created.
CarbonImmutable|null $cancelledAt The date indicating when the batch was cancelled.
CarbonImmutable|null $finishedAt The date indicating when the batch was finished.

Methods

void __construct(Factory $queue, BatchRepository $repository, string $id, string $name, int $totalJobs, int $pendingJobs, int $failedJobs, array $failedJobIds, array $options, CarbonImmutable $createdAt, CarbonImmutable|null $cancelledAt = null, CarbonImmutable|null $finishedAt = null)

Create a new batch instance.

Batch fresh()

Get a fresh instance of the batch represented by this ID.

Batch add(Collection|array $jobs)

Add additional jobs to the batch.

Collection prepareBatchedChain(array $chain)

Prepare a chain that exists within the jobs being added.

int processedJobs()

Get the total number of jobs that have been processed by the batch thus far.

int progress()

Get the percentage of jobs that have been processed (between 0-100).

void recordSuccessfulJob(string $jobId)

Record that a job within the batch finished successfully, executing any callbacks if necessary.

UpdatedBatchJobCounts decrementPendingJobs(string $jobId)

Decrement the pending jobs for the batch.

bool finished()

Determine if the batch has finished executing.

bool hasThenCallbacks()

Determine if the batch has "success" callbacks.

bool allowsFailures()

Determine if the batch allows jobs to fail without cancelling the batch.

bool hasFailures()

Determine if the batch has job failures.

void recordFailedJob(string $jobId, Throwable $e)

Record that a job within the batch failed to finish successfully, executing any callbacks if necessary.

UpdatedBatchJobCounts incrementFailedJobs(string $jobId)

Increment the failed jobs for the batch.

bool hasCatchCallbacks()

Determine if the batch has "catch" callbacks.

bool hasFinallyCallbacks()

Determine if the batch has "then" callbacks.

void cancel()

Cancel the batch.

bool canceled()

Determine if the batch has been cancelled.

bool cancelled()

Determine if the batch has been cancelled.

void delete()

Delete the batch from storage.

void invokeHandlerCallback(SerializableClosure|callable $handler, Batch $batch, Throwable $e = null)

Invoke a batch callback handler.

array toArray()

Convert the batch to an array.

array jsonSerialize()

Get the JSON serializable representation of the object.

Details

void __construct(Factory $queue, BatchRepository $repository, string $id, string $name, int $totalJobs, int $pendingJobs, int $failedJobs, array $failedJobIds, array $options, CarbonImmutable $createdAt, CarbonImmutable|null $cancelledAt = null, CarbonImmutable|null $finishedAt = null)

Create a new batch instance.

Parameters

Factory $queue
BatchRepository $repository
string $id
string $name
int $totalJobs
int $pendingJobs
int $failedJobs
array $failedJobIds
array $options
CarbonImmutable $createdAt
CarbonImmutable|null $cancelledAt
CarbonImmutable|null $finishedAt

Return Value

void

Batch fresh()

Get a fresh instance of the batch represented by this ID.

Return Value

Batch

Batch add(Collection|array $jobs)

Add additional jobs to the batch.

Parameters

Collection|array $jobs

Return Value

Batch

protected Collection prepareBatchedChain(array $chain)

Prepare a chain that exists within the jobs being added.

Parameters

array $chain

Return Value

Collection

int processedJobs()

Get the total number of jobs that have been processed by the batch thus far.

Return Value

int

int progress()

Get the percentage of jobs that have been processed (between 0-100).

Return Value

int

void recordSuccessfulJob(string $jobId)

Record that a job within the batch finished successfully, executing any callbacks if necessary.

Parameters

string $jobId

Return Value

void

UpdatedBatchJobCounts decrementPendingJobs(string $jobId)

Decrement the pending jobs for the batch.

Parameters

string $jobId

Return Value

UpdatedBatchJobCounts

bool finished()

Determine if the batch has finished executing.

Return Value

bool

bool hasThenCallbacks()

Determine if the batch has "success" callbacks.

Return Value

bool

bool allowsFailures()

Determine if the batch allows jobs to fail without cancelling the batch.

Return Value

bool

bool hasFailures()

Determine if the batch has job failures.

Return Value

bool

void recordFailedJob(string $jobId, Throwable $e)

Record that a job within the batch failed to finish successfully, executing any callbacks if necessary.

Parameters

string $jobId
Throwable $e

Return Value

void

UpdatedBatchJobCounts incrementFailedJobs(string $jobId)

Increment the failed jobs for the batch.

Parameters

string $jobId

Return Value

UpdatedBatchJobCounts

bool hasCatchCallbacks()

Determine if the batch has "catch" callbacks.

Return Value

bool

bool hasFinallyCallbacks()

Determine if the batch has "then" callbacks.

Return Value

bool

void cancel()

Cancel the batch.

Return Value

void

bool canceled()

Determine if the batch has been cancelled.

Return Value

bool

bool cancelled()

Determine if the batch has been cancelled.

Return Value

bool

void delete()

Delete the batch from storage.

Return Value

void

protected void invokeHandlerCallback(SerializableClosure|callable $handler, Batch $batch, Throwable $e = null)

Invoke a batch callback handler.

Parameters

SerializableClosure|callable $handler
Batch $batch
Throwable $e

Return Value

void

array toArray()

Convert the batch to an array.

Return Value

array

array jsonSerialize()

Get the JSON serializable representation of the object.

Return Value

array

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Bus/Batch.html