Posts tagged with queues

How to group queued jobs using Laravel 8's new Batch class

by Freek Van der Herten – 14 minute read

Laravel 8 offers a shiny new way to group multiple jobs into one batch. This will allow you to easily check how many job there are in a batch, what to total progress is and even cancel all jobs in a batch.

In this blog post, I'd like to share how we will use this feature in the upcoming v3 of Mailcoach. We'll also take a look at how batches are implemented under the hood in Laravel.

Read more

Watch the recording of Laravel Meetup #1

by Freek Van der Herten – 2 minute read

Yesterday, the very first Laravel Worldwide Meetup was held. At the event, which was live streamed on YouTube, Joseph Silber gave an introduction to lazy collections. Mohamed Said demonstrated some very powerful additions coming to queues in Laravel 8.

You can watch a recording of the meetup below.

Read more

Join 9,000+ developers

Every month, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

How to size & scale your Laravel Queues

ohdear.app

My buddy Mattias and I run a monitoring service called Oh Dear! We plan on regularly writing cool stuff on the technical and commericial challenges we face. Here's the first post on how we scale our queues.

Laravel offers a convenient way to create asynchronous background tasks using its queues. We utilize those heavily at Oh Dear! for all our monitoring jobs and in this post we'll share some of our lessons learned and what we consider to be best practices.

Read more [ohdear.app]

Setting up Laravel Horizon with Forge and Envoyer

Dries Vints, maintainer of Laravel.io, posted a step-by-step guide on how to get started with Laravel Horizon on a Forge provisioned server.

I recently installed Horizon for Laravel.io and while it wasn’t that hard to install, I still had to figure some things out. Since this was the first time setting everything up I thought I’d write up the steps to take to get started with Horizon and set everything up with Forge and Envoyer.

https://medium.com/@driesvints/laravel-horizon-with-forge-and-envoyer-82a7e819d69f

Read more

Partitioning for concurrency in synchronous business processes

On his blog Frank De Jonge, member of the PHP League and creator of Flysystem, explains a cool pragmatic solution how to ensure queued processes for the same user complete in the right order.

The use of multiple workers allows for much higher throughput, but it also allows for race conditions during processing. When messages for the same user are sent to different workers, handling order can no longer be guaranteed. Therefore we have failed to fulfil our business rule.

If we were able to ensure every message from the same user were sent to the same worker, the worker could ensure those messages are handled in order while the system as a whole would still benefit from the degree of parallelism. But how do we make this happen?

https://blog.frankdejonge.nl/parallelise-synchronous-business-processes/

Read more

Diving into Laravel Horizon

Laravel Horizon is a kickass dashboard for viewing queued jobs. Co-creator Mohammed Said published two posts about the inner working of the tool. The first one on the Diving Laravel site highlights the overall configuration and how the master supervisor works.

Laravel Horizon is a queue manager that gives you full control over your queues, it provides means to configure how your jobs are processed, generate analytics, and perform different queue-related tasks from within a nice dashboard.

In this dive we're going to learn how Horizon boots up and handles processing jobs using different workers as well as how it collects useful metrics for you to have the full picture of how your application dispatches and runs jobs.

https://divinglaravel.com/horizon/before-the-dive

The second one, published on his own blog, shows how queued jobs can get tagged.

Laravel Horizon is shipped with many amazing features that help you understand what goes on with your queue workers, my personal favorite feature is the ability to tag jobs for further investigation.

https://themsaid.com/tagging-jobs-in-laravel-horizon-20170731

Read more

Conditionally pushing event listeners to queue

Mohammed Said, Laravel employee #1 and diver, explains how you can avoid pushing unnecessary jobs to a queue.

How many customers will reach the 10K purchase milestone? does it make sense to push a Job to queue for every single purchase while there's a huge chance that this job will just do nothing at all? IMHO this is a waste of resources, you might end up filling your queue with thousands of unnecessary jobs.

It might be a good thing if we can check for that condition before queueing the listener.

http://themsaid.com/conditionally-queue-listeners-laravel-20170505/

Read more

V2 of laravel-failed-job-monitor has been released

by Freek Van der Herten – 1 minute read

In the beginning of the year we released a package to notify you when a queued job in your Laravel application fails. Today we tagged v2 of that laravel-failed-job-monitor package. The big change is that it now uses Laravel 5.3's native notification capabilities. So it's a cinch to modify the…

Read more

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.

Read more