Worker

class Worker (View source)

Properties

protected QueueManager $manager The queue manager instance.
protected Dispatcher $events The event dispatcher instance.
protected Repository $cache The cache repository implementation.
protected Handler $exceptions The exception handler instance.

Methods

void __construct(QueueManager $manager, Dispatcher $events, ExceptionHandler $exceptions)

Create a new queue worker.

void daemon(string $connectionName, string $queue, WorkerOptions $options)

Listen to the given queue in a loop.

void registerTimeoutHandler(WorkerOptions $options)

Register the worker timeout handler (PHP 7.1+).

bool daemonShouldRun(WorkerOptions $options)

Determine if the daemon should process on this iteration.

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

Process the next job on the queue.

Job|null getNextJob(Queue $connection, string $queue)

Get the next job from the queue connection.

void process(string $connectionName, Job $job, WorkerOptions $options)

Process a given job from the queue.

void handleJobException(string $connectionName, Job $job, WorkerOptions $options, Exception $e)

Handle an exception that occurred while the job was running.

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

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

void markJobAsFailedIfHasExceededMaxAttempts(string $connectionName, Job $job, int $maxTries, Exception $e)

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

void failJob(string $connectionName, Job $job, Exception $e)

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

void raiseBeforeJobEvent(string $connectionName, Job $job)

Raise the before queue job event.

void raiseAfterJobEvent(string $connectionName, Job $job)

Raise the after queue job event.

void raiseExceptionOccurredJobEvent(string $connectionName, Job $job, Exception $e)

Raise the exception occurred queue job event.

void raiseFailedJobEvent(string $connectionName, Job $job, Exception $e)

Raise the failed queue job event.

bool memoryExceeded(int $memoryLimit)

Determine if the memory limit has been exceeded.

void stop()

Stop listening and bail out of the script.

void sleep(int $seconds)

Sleep the script for a given number of seconds.

int|null getTimestampOfLastQueueRestart()

Get the last queue restart timestamp, or null.

bool queueShouldRestart(int|null $lastRestart)

Determine if the queue worker should restart.

void setCache(Repository $cache)

Set the cache repository implementation.

QueueManager getManager()

Get the queue manager instance.

void setManager(QueueManager $manager)

Set the queue manager instance.

Details

void __construct(QueueManager $manager, Dispatcher $events, ExceptionHandler $exceptions)

Create a new queue worker.

Parameters

QueueManager $manager
Dispatcher $events
ExceptionHandler $exceptions

Return Value

void

void daemon(string $connectionName, string $queue, WorkerOptions $options)

Listen to the given queue in a loop.

Parameters

string $connectionName
string $queue
WorkerOptions $options

Return Value

void

protected void registerTimeoutHandler(WorkerOptions $options)

Register the worker timeout handler (PHP 7.1+).

Parameters

WorkerOptions $options

Return Value

void

protected bool daemonShouldRun(WorkerOptions $options)

Determine if the daemon should process on this iteration.

Parameters

WorkerOptions $options

Return Value

bool

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

Process the next job on the queue.

Parameters

string $connectionName
string $queue
WorkerOptions $options

Return Value

void

protected Job|null getNextJob(Queue $connection, string $queue)

Get the next job from the queue connection.

Parameters

Queue $connection
string $queue

Return Value

Job|null

void process(string $connectionName, Job $job, WorkerOptions $options)

Process a given job from the queue.

Parameters

string $connectionName
Job $job
WorkerOptions $options

Return Value

void

Exceptions

Throwable

protected void handleJobException(string $connectionName, Job $job, WorkerOptions $options, Exception $e)

Handle an exception that occurred while the job was running.

Parameters

string $connectionName
Job $job
WorkerOptions $options
Exception $e

Return Value

void

Exceptions

Exception

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

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

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

Parameters

string $connectionName
Job $job
int $maxTries

Return Value

void

protected void markJobAsFailedIfHasExceededMaxAttempts(string $connectionName, Job $job, int $maxTries, Exception $e)

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

Parameters

string $connectionName
Job $job
int $maxTries
Exception $e

Return Value

void

protected void failJob(string $connectionName, Job $job, Exception $e)

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

Parameters

string $connectionName
Job $job
Exception $e

Return Value

void

protected void raiseBeforeJobEvent(string $connectionName, Job $job)

Raise the before queue job event.

Parameters

string $connectionName
Job $job

Return Value

void

protected void raiseAfterJobEvent(string $connectionName, Job $job)

Raise the after queue job event.

Parameters

string $connectionName
Job $job

Return Value

void

protected void raiseExceptionOccurredJobEvent(string $connectionName, Job $job, Exception $e)

Raise the exception occurred queue job event.

Parameters

string $connectionName
Job $job
Exception $e

Return Value

void

protected void raiseFailedJobEvent(string $connectionName, Job $job, Exception $e)

Raise the failed queue job event.

Parameters

string $connectionName
Job $job
Exception $e

Return Value

void

bool memoryExceeded(int $memoryLimit)

Determine if the memory limit has been exceeded.

Parameters

int $memoryLimit

Return Value

bool

void stop()

Stop listening and bail out of the script.

Return Value

void

void sleep(int $seconds)

Sleep the script for a given number of seconds.

Parameters

int $seconds

Return Value

void

protected int|null getTimestampOfLastQueueRestart()

Get the last queue restart timestamp, or null.

Return Value

int|null

protected bool queueShouldRestart(int|null $lastRestart)

Determine if the queue worker should restart.

Parameters

int|null $lastRestart

Return Value

bool

void setCache(Repository $cache)

Set the cache repository implementation.

Parameters

Repository $cache

Return Value

void

QueueManager getManager()

Get the queue manager instance.

Return Value

QueueManager

void setManager(QueueManager $manager)

Set the queue manager instance.

Parameters

QueueManager $manager

Return Value

void

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/5.3/Illuminate/Queue/Worker.html