class Illuminate / Queue / Worker
You're browsing the documentation for an upcoming version of Laravel. The documentation and features of this release are subject to change.

Worker

Uses

Constants

public

EXIT_SUCCESS

public

EXIT_ERROR

Default: 1
public

EXIT_MEMORY_LIMIT

Default: 12

Properties

protected

$name string

The name of the worker.

Default: null
protected

$manager Factory

The queue manager instance.

Default: null
protected

$events Dispatcher

The event dispatcher instance.

Default: null
protected

$cache Repository

The cache repository implementation.

Default: null
protected

$exceptions ExceptionHandler

The exception handler instance.

Default: null
protected

$isDownForMaintenance callable

The callback used to determine if the application is in maintenance mode.

Default: null
protected

$resetScope callable

The callback used to reset the application's scope.

Default: null
public

$shouldQuit bool

Indicates if the worker should exit.

Default: false
public

$paused bool

Indicates if the worker is paused.

Default: false
protected static

$popCallbacks callable[]

The callbacks used to pop jobs from queues.

Default: []

Methods

public

__construct ( Factory $manager , Dispatcher $events , ExceptionHandler $exceptions , callable $isDownForMaintenance , callable $resetScope ) : void

Create a new queue worker.

Parameters

public

daemon ( $connectionName , $queue , WorkerOptions $options ) : int

Listen to the given queue in a loop.

Parameters

protected

registerTimeoutHandler ( $job , WorkerOptions $options ) : void

Register the worker timeout handler.

Parameters

protected

resetTimeoutHandler ( ) : void

Reset the worker timeout handler.

protected

timeoutForJob ( $job , WorkerOptions $options ) : int

Get the appropriate timeout for the given job.

Parameters

protected

daemonShouldRun ( WorkerOptions $options , $connectionName , $queue ) : bool

Determine if the daemon should process on this iteration.

Parameters

protected

pauseWorker ( WorkerOptions $options , $lastRestart ) : int|null

Pause the worker for the current loop.

Parameters

protected

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
public

runNextJob ( $connectionName , $queue , WorkerOptions $options ) : void

Process the next job on the queue.

Parameters

protected

getNextJob ( $connection , $queue ) : Job |null

Get the next job from the queue connection.

Parameters

  • $connection Queue
  • $queue string
protected

runJob ( $job , $connectionName , WorkerOptions $options ) : void

Process the given job.

Parameters

protected

stopWorkerIfLostConnection ( $e ) : void

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

Parameters

public

process ( $connectionName , $job , WorkerOptions $options ) : void

Process the given job from the queue.

Parameters

protected

handleJobException ( $connectionName , $job , WorkerOptions $options , Throwable $e ) : void

Handle an exception that occurred while the job was running.

Parameters

protected

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
protected

markJobAsFailedIfWillExceedMaxAttempts ( $connectionName , $job , $maxTries , Throwable $e ) : void

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

Parameters

protected

markJobAsFailedIfWillExceedMaxExceptions ( $connectionName , $job , Throwable $e ) : void

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

Parameters

protected

markJobAsFailedIfItShouldFailOnTimeout ( $connectionName , $job , Throwable $e ) : void

Mark the given job as failed if it should fail on timeouts.

Parameters

protected

failJob ( $job , Throwable $e ) : void

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

Parameters

protected

calculateBackoff ( $job , WorkerOptions $options ) : int

Calculate the backoff for the given job.

Parameters

protected

raiseBeforeJobPopEvent ( $connectionName ) : void

Raise the before job has been popped.

Parameters

  • $connectionName string
protected

raiseAfterJobPopEvent ( $connectionName , $job ) : void

Raise the after job has been popped.

Parameters

  • $connectionName string
  • $job Job |null
protected

raiseBeforeJobEvent ( $connectionName , $job ) : void

Raise the before queue job event.

Parameters

  • $connectionName string
  • $job Job
protected

raiseAfterJobEvent ( $connectionName , $job ) : void

Raise the after queue job event.

Parameters

  • $connectionName string
  • $job Job
protected

raiseExceptionOccurredJobEvent ( $connectionName , $job , Throwable $e ) : void

Raise the exception occurred queue job event.

Parameters

protected

queueShouldRestart ( $lastRestart ) : bool

Determine if the queue worker should restart.

Parameters

  • $lastRestart int|null
protected

getTimestampOfLastQueueRestart ( ) : int|null

Get the last queue restart timestamp, or null.

protected

listenForSignals ( ) : void

Enable async signals for the process.

protected

supportsAsyncSignals ( ) : bool

Determine if "async" signals are supported.

public

memoryExceeded ( $memoryLimit ) : bool

Determine if the memory limit has been exceeded.

Parameters

  • $memoryLimit int
public

stop ( $status , $options ) : int

Stop listening and bail out of the script.

Parameters

  • $status int
  • $options WorkerOptions|null
public

kill ( $status , $options ) : never

Kill the process.

Parameters

protected

maxAttemptsExceededException ( $job ) : MaxAttemptsExceededException

Create an instance of MaxAttemptsExceededException.

Parameters

protected

timoutExceededException ( $job ) : TimeoutExceededException

Create an instance of TimeoutExceededException.

Parameters

public

sleep ( $seconds ) : void

Sleep the script for a given number of seconds.

Parameters

  • $seconds int|float
public

setCache ( Repository $cache ) : $this

Set the cache repository implementation.

Parameters

public

setName ( $name ) : $this

Set the name of the worker.

Parameters

  • $name string
public static

popUsing ( $workerName , $callback ) : void

Register a callback to be executed to pick jobs.

Parameters

  • $workerName string
  • $callback callable
public

getManager ( ) : Factory

Get the queue manager instance.

public

setManager ( Factory $manager ) : void

Set the queue manager instance.

Parameters