Documentation

Worker
in package
Uses DetectsLostConnections

Table of Contents

$paused  : bool
Indicates if the worker is paused.
$shouldQuit  : bool
Indicates if the worker should exit.
$cache  : Repository
The cache repository implementation.
$events  : Dispatcher
The event dispatcher instance.
$exceptions  : ExceptionHandler
The exception handler instance.
$manager  : QueueManager
The queue manager instance.
__construct()  : void
Create a new queue worker.
daemon()  : void
Listen to the given queue in a loop.
getManager()  : QueueManager
Get the queue manager instance.
kill()  : void
Kill the process.
memoryExceeded()  : bool
Determine if the memory limit has been exceeded.
process()  : void
Process the given job from the queue.
runNextJob()  : void
Process the next job on the queue.
setCache()  : void
Set the cache repository implementation.
setManager()  : void
Set the queue manager instance.
sleep()  : void
Sleep the script for a given number of seconds.
stop()  : void
Stop listening and bail out of the script.
causedByLostConnection()  : bool
Determine if the given exception was caused by a lost connection.
daemonShouldRun()  : bool
Determine if the daemon should process on this iteration.
failJob()  : void
Mark the given job as failed and raise the relevant event.
getNextJob()  : Job|null
Get the next job from the queue connection.
getTimestampOfLastQueueRestart()  : int|null
Get the last queue restart timestamp, or null.
handleJobException()  : void
Handle an exception that occurred while the job was running.
listenForSignals()  : void
Enable async signals for the process.
markJobAsFailedIfAlreadyExceedsMaxAttempts()  : void
Mark the given job as failed if it has exceeded the maximum allowed attempts.
markJobAsFailedIfWillExceedMaxAttempts()  : void
Mark the given job as failed if it has exceeded the maximum allowed attempts.
pauseWorker()  : void
Pause the worker for the current loop.
queueShouldRestart()  : bool
Determine if the queue worker should restart.
raiseAfterJobEvent()  : void
Raise the after queue job event.
raiseBeforeJobEvent()  : void
Raise the before queue job event.
raiseExceptionOccurredJobEvent()  : void
Raise the exception occurred queue job event.
raiseFailedJobEvent()  : void
Raise the failed queue job event.
registerTimeoutHandler()  : void
Register the worker timeout handler (PHP 7.1+).
runJob()  : void
Process the given job.
stopIfNecessary()  : mixed
Stop the process if necessary.
stopWorkerIfLostConnection()  : void
Stop the worker if we have lost connection to a database.
supportsAsyncSignals()  : bool
Determine if "async" signals are supported.
timeoutForJob()  : int
Get the appropriate timeout for the given job.

Properties

$paused

Indicates if the worker is paused.

public bool $paused = false

$shouldQuit

Indicates if the worker should exit.

public bool $shouldQuit = false

Methods

daemon()

Listen to the given queue in a loop.

public daemon(string $connectionName, string $queue, WorkerOptions $options) : void
Parameters
$connectionName : string
$queue : string
$options : WorkerOptions
Return values
void

kill()

Kill the process.

public kill(int $status) : void
Parameters
$status : int
Return values
void

memoryExceeded()

Determine if the memory limit has been exceeded.

public memoryExceeded(int $memoryLimit) : bool
Parameters
$memoryLimit : int
Return values
bool

process()

Process the given job from the queue.

public process(string $connectionName, Job $job, WorkerOptions $options) : void
Parameters
$connectionName : string
$job : Job
$options : WorkerOptions
Tags
throws
Throwable
Return values
void

runNextJob()

Process the next job on the queue.

public runNextJob(string $connectionName, string $queue, WorkerOptions $options) : void
Parameters
$connectionName : string
$queue : string
$options : WorkerOptions
Return values
void

setCache()

Set the cache repository implementation.

public setCache(Repository $cache) : void
Parameters
$cache : Repository
Return values
void

setManager()

Set the queue manager instance.

public setManager(QueueManager $manager) : void
Parameters
$manager : QueueManager
Return values
void

sleep()

Sleep the script for a given number of seconds.

public sleep(int|float $seconds) : void
Parameters
$seconds : int|float
Return values
void

stop()

Stop listening and bail out of the script.

public stop(int $status) : void
Parameters
$status : int
Return values
void

causedByLostConnection()

Determine if the given exception was caused by a lost connection.

protected causedByLostConnection(Exception $e) : bool
Parameters
$e : Exception
Return values
bool

daemonShouldRun()

Determine if the daemon should process on this iteration.

protected daemonShouldRun(WorkerOptions $options, string $connectionName, string $queue) : bool
Parameters
$options : WorkerOptions
$connectionName : string
$queue : string
Return values
bool

failJob()

Mark the given job as failed and raise the relevant event.

protected failJob(string $connectionName, Job $job, Exception $e) : void
Parameters
$connectionName : string
$job : Job
$e : Exception
Return values
void

getNextJob()

Get the next job from the queue connection.

protected getNextJob(Queue $connection, string $queue) : Job|null
Parameters
$connection : Queue
$queue : string
Return values
Job|null

getTimestampOfLastQueueRestart()

Get the last queue restart timestamp, or null.

protected getTimestampOfLastQueueRestart() : int|null
Return values
int|null

handleJobException()

Handle an exception that occurred while the job was running.

protected handleJobException(string $connectionName, Job $job, WorkerOptions $options, Exception $e) : void
Parameters
$connectionName : string
$job : Job
$options : WorkerOptions
$e : Exception
Tags
throws
Exception
Return values
void

listenForSignals()

Enable async signals for the process.

protected listenForSignals() : void
Return values
void

markJobAsFailedIfAlreadyExceedsMaxAttempts()

Mark the given job as failed if it has exceeded the maximum allowed attempts.

protected markJobAsFailedIfAlreadyExceedsMaxAttempts(string $connectionName, Job $job, int $maxTries) : void

This will likely be because the job previously exceeded a timeout.

Parameters
$connectionName : string
$job : Job
$maxTries : int
Return values
void

markJobAsFailedIfWillExceedMaxAttempts()

Mark the given job as failed if it has exceeded the maximum allowed attempts.

protected markJobAsFailedIfWillExceedMaxAttempts(string $connectionName, Job $job, int $maxTries, Exception $e) : void
Parameters
$connectionName : string
$job : Job
$maxTries : int
$e : Exception
Return values
void

pauseWorker()

Pause the worker for the current loop.

protected pauseWorker(WorkerOptions $options, int $lastRestart) : void
Parameters
$options : WorkerOptions
$lastRestart : int
Return values
void

queueShouldRestart()

Determine if the queue worker should restart.

protected queueShouldRestart(int|null $lastRestart) : bool
Parameters
$lastRestart : int|null
Return values
bool

raiseAfterJobEvent()

Raise the after queue job event.

protected raiseAfterJobEvent(string $connectionName, Job $job) : void
Parameters
$connectionName : string
$job : Job
Return values
void

raiseBeforeJobEvent()

Raise the before queue job event.

protected raiseBeforeJobEvent(string $connectionName, Job $job) : void
Parameters
$connectionName : string
$job : Job
Return values
void

raiseExceptionOccurredJobEvent()

Raise the exception occurred queue job event.

protected raiseExceptionOccurredJobEvent(string $connectionName, Job $job, Exception $e) : void
Parameters
$connectionName : string
$job : Job
$e : Exception
Return values
void

raiseFailedJobEvent()

Raise the failed queue job event.

protected raiseFailedJobEvent(string $connectionName, Job $job, Exception $e) : void
Parameters
$connectionName : string
$job : Job
$e : Exception
Return values
void

registerTimeoutHandler()

Register the worker timeout handler (PHP 7.1+).

protected registerTimeoutHandler(Job|null $job, WorkerOptions $options) : void
Parameters
$job : Job|null
$options : WorkerOptions
Return values
void

runJob()

Process the given job.

protected runJob(Job $job, string $connectionName, WorkerOptions $options) : void
Parameters
$job : Job
$connectionName : string
$options : WorkerOptions
Return values
void

stopIfNecessary()

Stop the process if necessary.

protected stopIfNecessary(WorkerOptions $options, int $lastRestart) : mixed
Parameters
$options : WorkerOptions
$lastRestart : int
Return values
mixed

stopWorkerIfLostConnection()

Stop the worker if we have lost connection to a database.

protected stopWorkerIfLostConnection(Exception $e) : void
Parameters
$e : Exception
Return values
void

supportsAsyncSignals()

Determine if "async" signals are supported.

protected supportsAsyncSignals() : bool
Return values
bool

timeoutForJob()

Get the appropriate timeout for the given job.

protected timeoutForJob(Job|null $job, WorkerOptions $options) : int
Parameters
$job : Job|null
$options : WorkerOptions
Return values
int

Search results