abstract class Job implements Job

Traits

Properties

protected mixed $instance

The job handler instance.

protected array|null $decodedPayload

The validated job payload.

protected InvalidPayloadException|null $payloadException

The exception raised while validating the job payload.

protected Container $container

The IoC container instance.

protected bool $deleted

Indicates if the job has been deleted.

protected bool $released

Indicates if the job has been released.

protected bool $failed

Indicates if the job has failed.

protected string $connectionName

The name of the connection the job belongs to.

protected string $queue

The name of the queue the job belongs to.

protected Lease|null $poolLease

The lease pinning this job's pooled backend until a terminal operation.

protected bool $poolLeaseAttached

Indicates whether this job has ever carried a pool lease.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

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

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $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|null $endTime = null)

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

int|string|null
getJobId()

Get the job identifier.

string
getRawBody()

Get the raw body of the job.

Job
withPoolLease(Lease $lease)

Attach the backend lease held for this job.

void
onPoolLeaseAttached()

Initialize state that must be captured while the backend is pinned.

void
releasePoolLease()

Return the pinned backend to its pool.

void
discardPoolLease()

Discard the pinned backend instead of returning it to its pool.

bool
poolLeaseIsFinalized()

Determine whether a previously attached backend lease is finalized.

never
discardPoolLeaseAfterFailure(Throwable $exception)

Discard a backend after failure without masking the primary exception.

string|null
uuid()

Get the UUID of the job.

void
fire()

Fire the job.

void
delete()

Delete the job from the queue.

bool
isDeleted()

Determine if the job has been deleted.

void
release(int $delay = 0)

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

bool
isReleased()

Determine if the job was released back into the queue.

bool
isDeletedOrReleased()

Determine if the job has been deleted or released.

bool
hasFailed()

Determine if the job has been marked as a failure.

void
markAsFailed()

Mark the job as "failed".

void
fail(Throwable|null $e = null)

Delete the job, call the "failed" method, and raise the failed job event.

bool
shouldRollBackDatabaseTransaction(Throwable|null $e)

Determine if the current database transaction should be rolled back to level zero.

void
failed(Throwable|null $e)

Process an exception that caused the job to fail.

mixed
resolve(string $class)

Resolve the given class.

mixed
getResolvedJob()

Get the resolved job handler instance.

array
payload()

Get the decoded body of the job.

int|null
maxTries()

Get the number of times to attempt a job.

int|null
maxExceptions()

Get the number of times to attempt a job after an exception.

bool
shouldFailOnTimeout()

Determine if the job should fail when it timeouts.

array|int|null
backoff()

The number of seconds to wait before retrying a job that encountered an uncaught exception.

int|null
timeout()

Get the number of seconds the job can run.

int|null
retryUntil()

Get the timestamp indicating when the job should timeout.

string
getName()

Get the name of the queued job class.

string
resolveName()

Get the resolved name of the queued job class.

string
resolveQueuedJobClass()

Get the class of the queued job.

string
getConnectionName()

Get the name of the connection the job belongs to.

string
getQueue()

Get the name of the queue the job belongs to.

getContainer()

Get the service container instance.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

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

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

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

Parameters

float $startTime
float|null $endTime

Return Value

string

at line 85
abstract int|string|null getJobId()

Get the job identifier.

Return Value

int|string|null

at line 90
abstract string getRawBody()

Get the raw body of the job.

Return Value

string

at line 95
Job withPoolLease(Lease $lease)

Attach the backend lease held for this job.

Parameters

Lease $lease

Return Value

Job

at line 113
protected void onPoolLeaseAttached()

Initialize state that must be captured while the backend is pinned.

Return Value

void

at line 120
protected void releasePoolLease()

Return the pinned backend to its pool.

Return Value

void

at line 131
protected void discardPoolLease()

Discard the pinned backend instead of returning it to its pool.

Return Value

void

at line 142
protected bool poolLeaseIsFinalized()

Determine whether a previously attached backend lease is finalized.

Return Value

bool

at line 150
protected never discardPoolLeaseAfterFailure(Throwable $exception)

Discard a backend after failure without masking the primary exception.

Parameters

Throwable $exception

Return Value

never

at line 164
string|null uuid()

Get the UUID of the job.

Return Value

string|null

at line 172
void fire()

Fire the job.

Return Value

void

at line 184
void delete()

Delete the job from the queue.

Return Value

void

at line 192
bool isDeleted()

Determine if the job has been deleted.

Return Value

bool

at line 200
void release(int $delay = 0)

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

Parameters

int $delay

Return Value

void

at line 208
bool isReleased()

Determine if the job was released back into the queue.

Return Value

bool

at line 216
bool isDeletedOrReleased()

Determine if the job has been deleted or released.

Return Value

bool

at line 224
bool hasFailed()

Determine if the job has been marked as a failure.

Return Value

bool

at line 232
void markAsFailed()

Mark the job as "failed".

Return Value

void

at line 240
void fail(Throwable|null $e = null)

Delete the job, call the "failed" method, and raise the failed job event.

Parameters

Throwable|null $e

Return Value

void

at line 300
protected bool shouldRollBackDatabaseTransaction(Throwable|null $e)

Determine if the current database transaction should be rolled back to level zero.

Parameters

Throwable|null $e

Return Value

bool

at line 316
protected void failed(Throwable|null $e)

Process an exception that caused the job to fail.

Parameters

Throwable|null $e

Return Value

void

at line 330
protected mixed resolve(string $class)

Resolve the given class.

Parameters

string $class

Return Value

mixed

at line 338
mixed getResolvedJob()

Get the resolved job handler instance.

Return Value

mixed

at line 346
array payload()

Get the decoded body of the job.

Return Value

array

at line 387
int|null maxTries()

Get the number of times to attempt a job.

Return Value

int|null

at line 395
int|null maxExceptions()

Get the number of times to attempt a job after an exception.

Return Value

int|null

at line 403
bool shouldFailOnTimeout()

Determine if the job should fail when it timeouts.

Return Value

bool

at line 413
array|int|null backoff()

The number of seconds to wait before retrying a job that encountered an uncaught exception.

Return Value

array|int|null

at line 421
int|null timeout()

Get the number of seconds the job can run.

Return Value

int|null

at line 429
int|null retryUntil()

Get the timestamp indicating when the job should timeout.

Return Value

int|null

at line 437
string getName()

Get the name of the queued job class.

Return Value

string

at line 447
string resolveName()

Get the resolved name of the queued job class.

Resolves the name of "wrapped" jobs such as class-based handlers.

Return Value

string

at line 457
string resolveQueuedJobClass()

Get the class of the queued job.

Resolves the class of "wrapped" jobs such as class-based handlers.

Return Value

string

at line 465
string getConnectionName()

Get the name of the connection the job belongs to.

Return Value

string

at line 473
string getQueue()

Get the name of the queue the job belongs to.

Return Value

string

at line 481
Container getContainer()

Get the service container instance.

Return Value

Container