Back Button Laravel

Queue it Up

Learning about queues can be a daunting task. It's not fun to be met with confusing jargon that you can't decipher. But that's what I'm here for. Let's incrementally break it all down into small steps that anyone can understand. In no time, you'll be throwing delayed jobs onto the queue like a pro.

Intermediate
Difficulty
11 episodes
1:16:40 hrs
Start Series
  • Latest Episode: Source Diving the Queue Worker

  • Like this series? Share the love!

  1. Section 1 The Essentials

    1. Run Time 2:27 Free

      Before we write a single line of code, give me two minutes to provide a real-life illustration of queues and workers. We'll use the example of a pizza delivery restaurant.

    2. Now that you have a basic idea of what a queue is, let's dispatch our first job using Laravel. We'll also learn about delayed job execution, and when you might reach for it.

    3. Now that you understand how to dispatch a simple closure, let's next create a dedicated Job class, while discussing serialization and daemons.

    4. Run Time 1:18

      We've learned how to use the global dispatch() function, but there's an alternative option you should consider as well. By default, each Job class includes a Dispatchable trait.

    5. Run Time 5:05

      So far, we've reviewed the "happy path" for a job, but what if an error or exception is thrown along the way? If you don't specify a maximum number of tries for your queue worker, the job will retry over and over again. In this episode, we'll learn how to fix this by creating a "failed_jobs" table.

    6. When working with queues, it can often prove difficult to see what's happening. For example, how many jobs ran in the last hour? Did any of them fail? How many workers are running? And what about only the jobs that match a particular tag? Let's solve this by installing Laravel Horizon, a dashboard for your Redis-backed queues.

    7. In this episode, we'll review how to create multiple queue stacks and workers, as well as when and why you might do so.

    8. If you don't have much control over the environment your application runs in, you might consider using the database queue connection. With this approach, rather than using Redis or Memcached, your jobs will instead be stored and fetched from the database.

    9. Before we dig in to learn how Laravel dispatches jobs to the queue, we must first learn about pipelines. It's possible that you've never come across Laravel's Pipeline API! It's a fluent interface for sending an object or piece of data through a series of "pipes," each of which has the opportunity to modify or verify it in some way.

  2. Section 2 Source Diving

    1. Now that you understand how pipelines work, let's dive into the Laravel source code to figure out what precisely happens when we call ReconcileAccount::dispatch($user).

    2. Source diving isn't always the most enjoyable thing in the world, but, nonetheless, it's an excellent way to improve your understanding of an API. In this episode, we'll learn what happens when a queued job is dispatched, as well as how the worker executes the job in a separate request.

Series still in development robot

*Series still in development. Check back often for updates.