Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Latest commit

 

History

History
38 lines (29 loc) · 1.88 KB

5.Workers.md

File metadata and controls

38 lines (29 loc) · 1.88 KB

Documentation - Workers

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.

Worker stop conditions

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.

Navigation

Previous page: Queue Aware Next page: Events

  1. Introduction
  2. Configuration
  3. Jobs
  4. QueueAware
  5. Workers
  6. Events
  7. Worker management