After queues are configured, jobs classes are written and pushed into a queue, they
must be popped out by a worker to be executed. This is done, as explained in the introduction, by
workers. A worker for SlmQueue is a class implementing the SlmQueue\Worker\WorkerInterface
.
A worker is started by by calling its processQueue($queue, array $options = [])
method. The $queue
parameter is
a string and should be the service name of the queue as registered in the queue plugin manager. The $options
parameter
is an optional array which is directly passed on to the pop()
method of the queue. This can contain flags specifically
for the different queue implementations.
The worker will be a long running call, due to the while(...){ /*...*/ }
loop it
contains inside the processQueue()
method. However, there are reasons to cancel the loop and stop the worker to
continue. PHP is not the best language for creating infinite running scripts.
It is wise to abort the script frequently, for example after x number of cycles in the while
loop.
Various build-in strategies ('see 6.Events') are used to decide if the worker should exit. These
strategies are aggregate listeners that hook into events the worker dispatches. A listener (to 'process.queue' or 'process.idle') may shortcut the event flow simply be returning a ExitWorkerLoopResult::withReason('a reason')
. The
worker will inspect the response collection.
Previous page: Queue Aware Next page: Events