Worker
Uses
Constants
EXIT_SUCCESS
EXIT_ERROR
EXIT_MEMORY_LIMIT
Properties
$name string
The name of the worker.
$isDownForMaintenance callable
The callback used to determine if the application is in maintenance mode.
$resetScope callable
The callback used to reset the application's scope.
$shouldQuit bool
Indicates if the worker should exit.
$paused bool
Indicates if the worker is paused.
$popCallbacks callable[]
The callbacks used to pop jobs from queues.
Methods
__construct ( Factory $manager , Dispatcher $events , ExceptionHandler $exceptions , callable $isDownForMaintenance , callable $resetScope ) : void
Create a new queue worker.
Parameters
- $manager Factory
- $events Dispatcher
- $exceptions ExceptionHandler
- $isDownForMaintenance callable
- $resetScope callable|null
daemon ( $connectionName , $queue , WorkerOptions $options ) : int
Listen to the given queue in a loop.
Parameters
- $connectionName string
- $queue string
- $options WorkerOptions
registerTimeoutHandler ( $job , WorkerOptions $options ) : void
Register the worker timeout handler.
Parameters
- $job Job |null
- $options WorkerOptions
resetTimeoutHandler ( ) : void
Reset the worker timeout handler.
timeoutForJob ( $job , WorkerOptions $options ) : int
Get the appropriate timeout for the given job.
Parameters
- $job Job |null
- $options WorkerOptions
daemonShouldRun ( WorkerOptions $options , $connectionName , $queue ) : bool
Determine if the daemon should process on this iteration.
Parameters
- $options WorkerOptions
- $connectionName string
- $queue string
pauseWorker ( WorkerOptions $options , $lastRestart ) : int|null
Pause the worker for the current loop.
Parameters
- $options WorkerOptions
- $lastRestart int
stopIfNecessary ( WorkerOptions $options , $lastRestart , $startTime , $jobsProcessed , $job ) : int|null
Determine the exit code to stop the process if necessary.
Parameters
- $options WorkerOptions
- $lastRestart int
- $startTime int
- $jobsProcessed int
- $job mixed
runNextJob ( $connectionName , $queue , WorkerOptions $options ) : void
Process the next job on the queue.
Parameters
- $connectionName string
- $queue string
- $options WorkerOptions
getNextJob ( $connection , $queue ) : Job |null
Get the next job from the queue connection.
Parameters
- $connection Queue
- $queue string
runJob ( $job , $connectionName , WorkerOptions $options ) : void
Process the given job.
Parameters
- $job Job
- $connectionName string
- $options WorkerOptions
stopWorkerIfLostConnection ( $e ) : void
Stop the worker if we have lost connection to a database.
Parameters
- $e Throwable
process ( $connectionName , $job , WorkerOptions $options ) : void
Process the given job from the queue.
Parameters
- $connectionName string
- $job Job
- $options WorkerOptions
handleJobException ( $connectionName , $job , WorkerOptions $options , Throwable $e ) : void
Handle an exception that occurred while the job was running.
Parameters
- $connectionName string
- $job Job
- $options WorkerOptions
- $e Throwable
markJobAsFailedIfAlreadyExceedsMaxAttempts ( $connectionName , $job , $maxTries ) : void
Mark the given job as failed if it has exceeded the maximum allowed attempts.
Parameters
- $connectionName string
- $job Job
- $maxTries int
markJobAsFailedIfWillExceedMaxAttempts ( $connectionName , $job , $maxTries , Throwable $e ) : void
Mark the given job as failed if it has exceeded the maximum allowed attempts.
Parameters
markJobAsFailedIfWillExceedMaxExceptions ( $connectionName , $job , Throwable $e ) : void
Mark the given job as failed if it has exceeded the maximum allowed attempts.
Parameters
markJobAsFailedIfItShouldFailOnTimeout ( $connectionName , $job , Throwable $e ) : void
Mark the given job as failed if it should fail on timeouts.
Parameters
failJob ( $job , Throwable $e ) : void
Mark the given job as failed and raise the relevant event.
Parameters
calculateBackoff ( $job , WorkerOptions $options ) : int
Calculate the backoff for the given job.
Parameters
- $job Job
- $options WorkerOptions
raiseBeforeJobPopEvent ( $connectionName ) : void
Raise the before job has been popped.
Parameters
- $connectionName string
raiseAfterJobPopEvent ( $connectionName , $job ) : void
Raise the after job has been popped.
Parameters
- $connectionName string
- $job Job |null
raiseBeforeJobEvent ( $connectionName , $job ) : void
Raise the before queue job event.
Parameters
- $connectionName string
- $job Job
raiseAfterJobEvent ( $connectionName , $job ) : void
Raise the after queue job event.
Parameters
- $connectionName string
- $job Job
raiseExceptionOccurredJobEvent ( $connectionName , $job , Throwable $e ) : void
Raise the exception occurred queue job event.
Parameters
queueShouldRestart ( $lastRestart ) : bool
Determine if the queue worker should restart.
Parameters
- $lastRestart int|null
getTimestampOfLastQueueRestart ( ) : int|null
Get the last queue restart timestamp, or null.
listenForSignals ( ) : void
Enable async signals for the process.
supportsAsyncSignals ( ) : bool
Determine if "async" signals are supported.
memoryExceeded ( $memoryLimit ) : bool
Determine if the memory limit has been exceeded.
Parameters
- $memoryLimit int
stop ( $status , $options ) : int
Stop listening and bail out of the script.
Parameters
- $status int
- $options WorkerOptions|null
kill ( $status , $options ) : never
Kill the process.
Parameters
- $status int
- $options WorkerOptions |null
maxAttemptsExceededException ( $job ) : MaxAttemptsExceededException
Create an instance of MaxAttemptsExceededException.
Parameters
- $job Job
timoutExceededException ( $job ) : TimeoutExceededException
Create an instance of TimeoutExceededException.
Parameters
- $job Job
sleep ( $seconds ) : void
Sleep the script for a given number of seconds.
Parameters
- $seconds int|float
setCache ( Repository $cache ) : $this
Set the cache repository implementation.
Parameters
- $cache Repository
setName ( $name ) : $this
Set the name of the worker.
Parameters
- $name string
popUsing ( $workerName , $callback ) : void
Register a callback to be executed to pick jobs.
Parameters
- $workerName string
- $callback callable