Skip to content

07.Worker

Muhammet ŞAFAK edited this page Aug 31, 2024 · 2 revisions

Worker

Worker is a worker function that is responsible for processing a message.

There are two important things you need to know about Worker;

  • Takes the message object as a parameter.
  • Each worker must return a boolean (or boolean castable value).
    • true means the operation was successful.
    • false means the operation failed and the message is put in a dead letter queue or re-added to the job queue to be tried again.

Workers can be defined as Closure for messages across the queue. See: Consumer Or a worker can be defined for a message type, independent of the queue workers. These are called JobMessages. See: JobMessage

Re-Try

If a worker encounters a temporary problem, it can immediately re-add the job to the queue to try again later. To do this, simply throw the \PHPQueueManager\PHPQueueManager\Exceptions\ReTryQueueException object with the error message.

throw new \PHPQueueManager\PHPQueueManager\Exceptions\ReTryQueueException("A network problem occurred.");

Dead Letter

If a worker encounters a persistent or critical problem, it can kill the job and add it to the dead letter queue. To do this, simply throw the \PHPQueueManager\PHPQueueManager\Exceptions\DeadLetterQueueException object with the error message.

throw new \PHPQueueManager\PHPQueueManager\Exceptions\DeadLetterQueueException("Unable to verify credit card number.");
Clone this wiki locally