class ChainedBatch implements ShouldQueue (View source)

Traits

Properties

string $batchId

The batch ID (if applicable).

from  Batchable
Job|null $job

The underlying queue job instance.

from  InteractsWithQueue
string|null $connection

The name of the connection the job should be sent to.

from  Queueable
string|null $queue

The name of the queue the job should be sent to.

from  Queueable
DateTimeInterface|DateInterval|array|int|null $delay

The number of seconds before the job should be made available.

from  Queueable
bool|null $afterCommit

Indicates whether the job should be dispatched after all database transactions have committed.

from  Queueable
array $middleware

The middleware the job should be dispatched through.

from  Queueable
array $chained

The jobs that should run if this job is successful.

from  Queueable
string|null $chainConnection

The name of the connection the chain should be sent to.

from  Queueable
string|null $chainQueue

The name of the queue the chain should be sent to.

from  Queueable
array|null $chainCatchCallbacks

The callbacks to be executed on chain failure.

from  Queueable
Collection $jobs

The collection of batched jobs.

string $name

The name of the batch.

array $options

The batch options.

Methods

Batch|null
batch()

Get the batch instance for the job, if applicable.

bool
batching()

Determine if the batch is still active and processing.

$this
withBatchId(string $batchId)

Set the batch ID on the job.

withFakeBatch(string $id = '', string $name = '', int $totalJobs = 0, int $pendingJobs = 0, int $failedJobs = 0, array $failedJobIds = [], array $options = [], CarbonImmutable|null $createdAt = null, CarbonImmutable|null $cancelledAt = null, CarbonImmutable|null $finishedAt = null)

Indicate that the job should use a fake batch.

static PendingDispatch
dispatch(mixed ...$arguments)

Dispatch the job with the given arguments.

dispatchIf(bool|Closure $boolean, mixed ...$arguments)

Dispatch the job with the given arguments if the given truth test passes.

dispatchUnless(bool|Closure $boolean, mixed ...$arguments)

Dispatch the job with the given arguments unless the given truth test passes.

static mixed
dispatchSync(mixed ...$arguments)

Dispatch a command to its appropriate handler in the current process.

static mixed
dispatchAfterResponse(mixed ...$arguments)

Dispatch a command to its appropriate handler after the current process.

static PendingChain
withChain(array $chain)

Set the jobs that should run if this job is successful.

int
secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float $endTime = null)

Given a start time, format the total run time for human readability.

int
attempts()

Get the number of times the job has been attempted.

void
delete()

Delete the job from the queue.

void
fail(Throwable|string|null $exception = null)

Fail the job from the queue.

void
release(DateTimeInterface|DateInterval|int $delay = 0)

Release the job back into the queue after (n) seconds.

$this
withFakeQueueInteractions()

Indicate that queue interactions like fail, delete, and release should be faked.

$this
assertDeleted()

Assert that the job was deleted from the queue.

$this
assertNotDeleted()

Assert that the job was not deleted from the queue.

$this
assertFailed()

Assert that the job was manually failed.

$this
assertNotFailed()

Assert that the job was not manually failed.

$this
assertReleased(DateTimeInterface|DateInterval|int $delay = null)

Assert that the job was released back onto the queue.

$this
assertNotReleased()

Assert that the job was not released back onto the queue.

$this
setJob(Job $job)

Set the base queue job instance.

$this
onConnection(BackedEnum|string|null $connection)

Set the desired connection for the job.

$this
onQueue(BackedEnum|string|null $queue)

Set the desired queue for the job.

$this
allOnConnection(BackedEnum|string|null $connection)

Set the desired connection for the chain.

$this
allOnQueue(BackedEnum|string|null $queue)

Set the desired queue for the chain.

$this
delay(DateTimeInterface|DateInterval|array|int|null $delay)

Set the desired delay in seconds for the job.

$this
withoutDelay()

Set the delay for the job to zero seconds.

$this
afterCommit()

Indicate that the job should be dispatched after all database transactions have committed.

$this
beforeCommit()

Indicate that the job should not wait until database transactions have been committed before dispatching.

$this
through(array|object $middleware)

Specify the middleware the job should be dispatched through.

$this
chain(array $chain)

Set the jobs that should run if this job is successful.

$this
prependToChain(mixed $job)

Prepend a job to the current chain so that it is run after the currently running job.

$this
appendToChain(mixed $job)

Append a job to the end of the current chain.

string
serializeJob(mixed $job)

Serialize a job for queuing.

void
dispatchNextJobInChain()

Dispatch the next job on the chain.

void
invokeChainCatchCallbacks(Throwable $e)

Invoke all of the chain's failed job callbacks.

void
assertHasChain(array $expectedChain)

Assert that the job has the given chain of jobs attached to it.

void
assertDoesntHaveChain()

Assert that the job has no remaining chained jobs.

void
__construct(PendingBatch $batch)

Create a new chained batch instance.

static Collection
prepareNestedBatches(Collection $jobs)

Prepare any nested batches within the given collection of jobs.

void
handle()

Handle the job.

toPendingBatch()

Convert the chained batch instance into a pending batch.

attachRemainderOfChainToEndOfBatch(PendingBatch $batch)

Move the remainder of the chain to a "finally" batch callback.

Details

Batch|null batch()

Get the batch instance for the job, if applicable.

Return Value

Batch|null

bool batching()

Determine if the batch is still active and processing.

Return Value

bool

$this withBatchId(string $batchId)

Set the batch ID on the job.

Parameters

string $batchId

Return Value

$this

withFakeBatch(string $id = '', string $name = '', int $totalJobs = 0, int $pendingJobs = 0, int $failedJobs = 0, array $failedJobIds = [], array $options = [], CarbonImmutable|null $createdAt = null, CarbonImmutable|null $cancelledAt = null, CarbonImmutable|null $finishedAt = null)

Indicate that the job should use a fake batch.

Parameters

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

static PendingDispatch dispatch(mixed ...$arguments)

Dispatch the job with the given arguments.

Parameters

mixed ...$arguments

Return Value

PendingDispatch

static PendingDispatch|Fluent dispatchIf(bool|Closure $boolean, mixed ...$arguments)

Dispatch the job with the given arguments if the given truth test passes.

Parameters

bool|Closure $boolean
mixed ...$arguments

Return Value

PendingDispatch|Fluent

static PendingDispatch|Fluent dispatchUnless(bool|Closure $boolean, mixed ...$arguments)

Dispatch the job with the given arguments unless the given truth test passes.

Parameters

bool|Closure $boolean
mixed ...$arguments

Return Value

PendingDispatch|Fluent

static mixed dispatchSync(mixed ...$arguments)

Dispatch a command to its appropriate handler in the current process.

Queueable jobs will be dispatched to the "sync" queue.

Parameters

mixed ...$arguments

Return Value

mixed

static mixed dispatchAfterResponse(mixed ...$arguments)

Dispatch a command to its appropriate handler after the current process.

Parameters

mixed ...$arguments

Return Value

mixed

static PendingChain withChain(array $chain)

Set the jobs that should run if this job is successful.

Parameters

array $chain

Return Value

PendingChain

protected int secondsUntil(DateTimeInterface|DateInterval|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected int availableAt(DateTimeInterface|DateInterval|int $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

int

protected DateTimeInterface|int parseDateInterval(DateTimeInterface|DateInterval|int $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

DateTimeInterface|int

protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

protected string runTimeForHumans(float $startTime, float $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float $endTime

Return Value

string

int attempts()

Get the number of times the job has been attempted.

Return Value

int

void delete()

Delete the job from the queue.

Return Value

void

void fail(Throwable|string|null $exception = null)

Fail the job from the queue.

Parameters

Throwable|string|null $exception

Return Value

void

void release(DateTimeInterface|DateInterval|int $delay = 0)

Release the job back into the queue after (n) seconds.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

void

$this withFakeQueueInteractions()

Indicate that queue interactions like fail, delete, and release should be faked.

Return Value

$this

$this assertDeleted()

Assert that the job was deleted from the queue.

Return Value

$this

$this assertNotDeleted()

Assert that the job was not deleted from the queue.

Return Value

$this

$this assertFailed()

Assert that the job was manually failed.

Return Value

$this

$this assertNotFailed()

Assert that the job was not manually failed.

Return Value

$this

$this assertReleased(DateTimeInterface|DateInterval|int $delay = null)

Assert that the job was released back onto the queue.

Parameters

DateTimeInterface|DateInterval|int $delay

Return Value

$this

$this assertNotReleased()

Assert that the job was not released back onto the queue.

Return Value

$this

$this setJob(Job $job)

Set the base queue job instance.

Parameters

Job $job

Return Value

$this

$this onConnection(BackedEnum|string|null $connection)

Set the desired connection for the job.

Parameters

BackedEnum|string|null $connection

Return Value

$this

$this onQueue(BackedEnum|string|null $queue)

Set the desired queue for the job.

Parameters

BackedEnum|string|null $queue

Return Value

$this

$this allOnConnection(BackedEnum|string|null $connection)

Set the desired connection for the chain.

Parameters

BackedEnum|string|null $connection

Return Value

$this

$this allOnQueue(BackedEnum|string|null $queue)

Set the desired queue for the chain.

Parameters

BackedEnum|string|null $queue

Return Value

$this

$this delay(DateTimeInterface|DateInterval|array|int|null $delay)

Set the desired delay in seconds for the job.

Parameters

DateTimeInterface|DateInterval|array|int|null $delay

Return Value

$this

$this withoutDelay()

Set the delay for the job to zero seconds.

Return Value

$this

$this afterCommit()

Indicate that the job should be dispatched after all database transactions have committed.

Return Value

$this

$this beforeCommit()

Indicate that the job should not wait until database transactions have been committed before dispatching.

Return Value

$this

$this through(array|object $middleware)

Specify the middleware the job should be dispatched through.

Parameters

array|object $middleware

Return Value

$this

$this chain(array $chain)

Set the jobs that should run if this job is successful.

Parameters

array $chain

Return Value

$this

$this prependToChain(mixed $job)

Prepend a job to the current chain so that it is run after the currently running job.

Parameters

mixed $job

Return Value

$this

$this appendToChain(mixed $job)

Append a job to the end of the current chain.

Parameters

mixed $job

Return Value

$this

protected string serializeJob(mixed $job)

Serialize a job for queuing.

Parameters

mixed $job

Return Value

string

Exceptions

RuntimeException

void dispatchNextJobInChain()

Dispatch the next job on the chain.

Return Value

void

void invokeChainCatchCallbacks(Throwable $e)

Invoke all of the chain's failed job callbacks.

Parameters

Throwable $e

Return Value

void

void assertHasChain(array $expectedChain)

Assert that the job has the given chain of jobs attached to it.

Parameters

array $expectedChain

Return Value

void

void assertDoesntHaveChain()

Assert that the job has no remaining chained jobs.

Return Value

void

void __construct(PendingBatch $batch)

Create a new chained batch instance.

Parameters

PendingBatch $batch

Return Value

void

static Collection prepareNestedBatches(Collection $jobs)

Prepare any nested batches within the given collection of jobs.

Parameters

Collection $jobs

Return Value

Collection

void handle()

Handle the job.

Return Value

void

PendingBatch toPendingBatch()

Convert the chained batch instance into a pending batch.

Return Value

PendingBatch

protected PendingBatch attachRemainderOfChainToEndOfBatch(PendingBatch $batch)

Move the remainder of the chain to a "finally" batch callback.

Parameters

PendingBatch $batch

Return Value

PendingBatch