Laravel Defibrillator: Keep Application Jobs Working At a Ordinary Rhythm

Laravel Defibrillator is a bundle by Michael Dyrynda that helps you guarantee that features of

Laravel Defibrillator is a bundle by Michael Dyrynda that helps you guarantee that features of your software must be jogging often are executing so.

This deal can enable by delaying the including of work opportunities to confused queue personnel though they catch up on a backlog of queue employment, for example:

Take into account a scheduled job that communicates with your application customers on a common interval. This scheduled process queues notifications to your consumers based on some affliction inside of your application. In a normal problem, there is a handful of notifications to go out, and they are dispatched with in a handful of seconds. But an software mistake causes your software to spiral out of manage. Queued notifications again up, your databases is not becoming current to flag notifications as possessing been sent, your error tracker floods with exceptions.

And then your scheduled undertaking operates yet again.

Out of the blue your queue has tens of hundreds of pending work opportunities in it and you’re trapped in a cycle that you can not keep up with.

This is an instance from the readme of how you could use this trait to retain an typical rhythm:

1// application/Console/Kernel.php



4// application/Positions/NotifyUsers.php

5community functionality tackle()


7 if ($this->hasAbnormalRhythm())

8 $this->defibrillate()


10 return



13 // Typical processing

14 $this->defibrillate()


You can also reduce lagging notifications from remaining sent if the heartbeat enters an irregular rhythm:

1// application/Notifications/CustomerNotification.php

2community operate shouldSend(): bool


4 return Cache::get('NotifyUsers')?->isFuture() ?? false


This deal has reasonable defaults for an interval concerning usual rhythms, which are customizable when using the package’s Defibrillator trait:

1use Defibrillator


3general public perform interval(): int


5 return 30


You can discover much more about this package, get total set up recommendations, and look at the source code on GitHub.