PHP Class Illuminate\Queue\Worker

Datei anzeigen Open project: illuminate/queue Class Usage Examples

Protected Properties

Property Type Description
$cache Illuminate\Contracts\Cache\Repository The cache repository implementation.
$events Illuminate\Contracts\Events\Dispatcher The event dispatcher instance.
$exceptions Illuminate\Foundation\Exceptions\Handler The exception handler instance.
$manager Illuminate\Queue\QueueManager The queue manager instance.

Public Methods

Method Description
__construct ( Illuminate\Queue\QueueManager $manager, Illuminate\Contracts\Events\Dispatcher $events, Illuminate\Contracts\Debug\ExceptionHandler $exceptions ) : void Create a new queue worker.
daemon ( string $connectionName, string $queue, WorkerOptions $options ) : void Listen to the given queue in a loop.
getManager ( ) : Illuminate\Queue\QueueManager Get the queue manager instance.
memoryExceeded ( integer $memoryLimit ) : boolean Determine if the memory limit has been exceeded.
process ( string $connectionName, Illuminate\Contracts\Queue\Job $job, WorkerOptions $options ) : void Process a given job from the queue.
runNextJob ( string $connectionName, string $queue, WorkerOptions $options ) : void Process the next job on the queue.
setCache ( Illuminate\Contracts\Cache\Repository $cache ) : void Set the cache repository implementation.
setManager ( Illuminate\Queue\QueueManager $manager ) : void Set the queue manager instance.
sleep ( integer $seconds ) : void Sleep the script for a given number of seconds.
stop ( ) : void Stop listening and bail out of the script.

Protected Methods

Method Description
daemonShouldRun ( WorkerOptions $options ) : boolean Determine if the daemon should process on this iteration.
failJob ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void Mark the given job as failed and raise the relevant event.
getNextJob ( Illuminate\Contracts\Queue\Queue $connection, string $queue ) : Illuminate\Contracts\Queue\Job | null Get the next job from the queue connection.
getTimestampOfLastQueueRestart ( ) : integer | null Get the last queue restart timestamp, or null.
handleJobException ( string $connectionName, Illuminate\Contracts\Queue\Job $job, WorkerOptions $options, Exception $e ) : void Handle an exception that occurred while the job was running.
markJobAsFailedIfAlreadyExceedsMaxAttempts ( string $connectionName, Illuminate\Contracts\Queue\Job $job, integer $maxTries ) : void Mark the given job as failed if it has exceeded the maximum allowed attempts.
markJobAsFailedIfHasExceededMaxAttempts ( string $connectionName, Illuminate\Contracts\Queue\Job $job, integer $maxTries, Exception $e ) : void Mark the given job as failed if it has exceeded the maximum allowed attempts.
queueShouldRestart ( integer | null $lastRestart ) : boolean Determine if the queue worker should restart.
raiseAfterJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job ) : void Raise the after queue job event.
raiseBeforeJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job ) : void Raise the before queue job event.
raiseExceptionOccurredJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void Raise the exception occurred queue job event.
raiseFailedJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void Raise the failed queue job event.
registerTimeoutHandler ( Illuminate\Contracts\Queue\Job | null $job, WorkerOptions $options ) : void Register the worker timeout handler (PHP 7.1+).
runJob ( Illuminate\Contracts\Queue\Job $job, string $connectionName, WorkerOptions $options ) : void Process the given job.

Method Details

__construct() public method

Create a new queue worker.
public __construct ( Illuminate\Queue\QueueManager $manager, Illuminate\Contracts\Events\Dispatcher $events, Illuminate\Contracts\Debug\ExceptionHandler $exceptions ) : void
$manager Illuminate\Queue\QueueManager
$events Illuminate\Contracts\Events\Dispatcher
$exceptions Illuminate\Contracts\Debug\ExceptionHandler
return void

daemon() public method

Listen to the given queue in a loop.
public daemon ( string $connectionName, string $queue, WorkerOptions $options ) : void
$connectionName string
$queue string
$options WorkerOptions
return void

daemonShouldRun() protected method

Determine if the daemon should process on this iteration.
protected daemonShouldRun ( WorkerOptions $options ) : boolean
$options WorkerOptions
return boolean

failJob() protected method

Mark the given job as failed and raise the relevant event.
protected failJob ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$e Exception
return void

getManager() public method

Get the queue manager instance.
public getManager ( ) : Illuminate\Queue\QueueManager
return Illuminate\Queue\QueueManager

getNextJob() protected method

Get the next job from the queue connection.
protected getNextJob ( Illuminate\Contracts\Queue\Queue $connection, string $queue ) : Illuminate\Contracts\Queue\Job | null
$connection Illuminate\Contracts\Queue\Queue
$queue string
return Illuminate\Contracts\Queue\Job | null

getTimestampOfLastQueueRestart() protected method

Get the last queue restart timestamp, or null.

handleJobException() protected method

Handle an exception that occurred while the job was running.
protected handleJobException ( string $connectionName, Illuminate\Contracts\Queue\Job $job, WorkerOptions $options, Exception $e ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$options WorkerOptions
$e Exception
return void

markJobAsFailedIfAlreadyExceedsMaxAttempts() protected method

This will likely be because the job previously exceeded a timeout.
protected markJobAsFailedIfAlreadyExceedsMaxAttempts ( string $connectionName, Illuminate\Contracts\Queue\Job $job, integer $maxTries ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$maxTries integer
return void

markJobAsFailedIfHasExceededMaxAttempts() protected method

Mark the given job as failed if it has exceeded the maximum allowed attempts.
protected markJobAsFailedIfHasExceededMaxAttempts ( string $connectionName, Illuminate\Contracts\Queue\Job $job, integer $maxTries, Exception $e ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$maxTries integer
$e Exception
return void

memoryExceeded() public method

Determine if the memory limit has been exceeded.
public memoryExceeded ( integer $memoryLimit ) : boolean
$memoryLimit integer
return boolean

process() public method

Process a given job from the queue.
public process ( string $connectionName, Illuminate\Contracts\Queue\Job $job, WorkerOptions $options ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$options WorkerOptions
return void

queueShouldRestart() protected method

Determine if the queue worker should restart.
protected queueShouldRestart ( integer | null $lastRestart ) : boolean
$lastRestart integer | null
return boolean

raiseAfterJobEvent() protected method

Raise the after queue job event.
protected raiseAfterJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
return void

raiseBeforeJobEvent() protected method

Raise the before queue job event.
protected raiseBeforeJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
return void

raiseExceptionOccurredJobEvent() protected method

Raise the exception occurred queue job event.
protected raiseExceptionOccurredJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$e Exception
return void

raiseFailedJobEvent() protected method

Raise the failed queue job event.
protected raiseFailedJobEvent ( string $connectionName, Illuminate\Contracts\Queue\Job $job, Exception $e ) : void
$connectionName string
$job Illuminate\Contracts\Queue\Job
$e Exception
return void

registerTimeoutHandler() protected method

Register the worker timeout handler (PHP 7.1+).
protected registerTimeoutHandler ( Illuminate\Contracts\Queue\Job | null $job, WorkerOptions $options ) : void
$job Illuminate\Contracts\Queue\Job | null
$options WorkerOptions
return void

runJob() protected method

Process the given job.
protected runJob ( Illuminate\Contracts\Queue\Job $job, string $connectionName, WorkerOptions $options ) : void
$job Illuminate\Contracts\Queue\Job
$connectionName string
$options WorkerOptions
return void

runNextJob() public method

Process the next job on the queue.
public runNextJob ( string $connectionName, string $queue, WorkerOptions $options ) : void
$connectionName string
$queue string
$options WorkerOptions
return void

setCache() public method

Set the cache repository implementation.
public setCache ( Illuminate\Contracts\Cache\Repository $cache ) : void
$cache Illuminate\Contracts\Cache\Repository
return void

setManager() public method

Set the queue manager instance.
public setManager ( Illuminate\Queue\QueueManager $manager ) : void
$manager Illuminate\Queue\QueueManager
return void

sleep() public method

Sleep the script for a given number of seconds.
public sleep ( integer $seconds ) : void
$seconds integer
return void

stop() public method

Stop listening and bail out of the script.
public stop ( ) : void
return void

Property Details

$cache protected_oe property

The cache repository implementation.
protected Repository,Illuminate\Contracts\Cache $cache
return Illuminate\Contracts\Cache\Repository

$events protected_oe property

The event dispatcher instance.
protected Dispatcher,Illuminate\Contracts\Events $events
return Illuminate\Contracts\Events\Dispatcher

$exceptions protected_oe property

The exception handler instance.
protected Handler,Illuminate\Foundation\Exceptions $exceptions
return Illuminate\Foundation\Exceptions\Handler

$manager protected_oe property

The queue manager instance.
protected QueueManager,Illuminate\Queue $manager
return Illuminate\Queue\QueueManager