-
Notifications
You must be signed in to change notification settings - Fork 0
07.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
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.");
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.");