Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!

Get notified when a queued job fails

Laravel provides excellent support for queued jobs. It’s very easy to put something on a queue and out of the box a lot of queue backends such as Beanstalkd, SQS and Redis are supported. Most of the time queued jobs will perform their job without any problem. But have you considered that a queued job can fail too?

Laravel can create a failed jobs table and write a record when a queued jobs fails. There is even a command to retry a failed job:

php artisan queue:retry 5

That’s nice! But how do you know if there is a job that failed? Sure you could check the failed jobs table from time to time, but I promise you after a while you won’t do that anymore. If you have many applications, checking all those failed job tables will get downright tedious.

To get notified when a queued job fails our intern Jolita created a package called failed job monitor. It hooks into the JobFailed-event Laravel 5.2 fires when a queued job fails. Once it is installed you will receive a mail whenever this event occurs. Integration with Slack comes built-in as well. Here’s how a Slack notification looks like:

failed job

Read the full instructions on how to install and use it on GitHub.

Freek Van der Herten is a partner and developer at Spatie, an Antwerp based company that specializes in creating web apps with Laravel. After hours he writes about modern PHP and Laravel on this blog. When not coding he’s probably rehearsing with his kraut rock band.