Retry is a new Laravel package from Alt Three which introduces a new command middleware.

The Retry package will retry a command a given number of times.

Installing Retry

composer require alt-three/retry  

Piping commands through to the RetryMiddleware is very simple if you're already using AltThree/Bus.

$dispatcher->mapUsing(function ($command) {
    return Dispatcher::simpleMapping($command, 'AltThree\Project\Bus', 'AltThree\Project\Bus\Handlers');


Using Retry

Your existing commands can now take three new properties:

  1. int $attempts - the total amount of times to retry the command.
  2. int $backoff - the time — in milliseconds — to wait before each retry.

Do note that the backoff time is actually an average. We actually wait for a random time within a 50% interval of the time you provide here in order to mitigate scenarios where resource locking is occurring.

A class may look like this:


namespace AltThree\Demo\Bus\Commands;

class DemoCommand  
     * The amount of retries to attempt.
     * @var int
    public $attempts = 5;

     * The backoff period.
     * @var int
    public $backoff = 10;
Share Comment on Twitter