This episode is for members only

Sign up to access "Build An Uptime Monitor with Inertia" right now.

Get started
Already a member? Sign in to continue
31. Setting up queues


Your progress
  • Total: 4h 59m
  • Played: 0m
  • Remaining: 4h 59m
Join or sign in to track your progress


We're now on to queuing, and if you're new to queues, we're going to go through in the Laravel docs setting up
database queues just to keep things really simple. We'll run our queue worker, and then in the next episode, we'll queue the endpoint check so this can be done in the background, rather than
having to rely on this taking up too many resources within the app itself. OK, so Laravel queues, the way that they work is we have jobs, which we've already created.
They are sent into a queue. We run a queue worker, and then they are run in sequence. Now, queues are incredibly powerful,
but for 80% of the time, we really just need to set up a basic queue worker and let all of the jobs that are created run through. Now, what we're queuing here are the checks themselves.
Remember, our scheduler is going to run every second. What that scheduler is going to do is determine which endpoints need to have an HTTP request made to them.
Once that happens, we're then going to queue the actual HTTP request within that job. And if we recall, the job that we created, if we head over to our job section,
is perform endpoint check. Within the app itself, doing all of this is not advisable. We want this to happen in the background. It's pretty much what queues are doing here.
So we're going to set up queues on the database just to keep things really simple. You can always switch this over to another driver if you need to.
So let's head down to the driver notes and prerequisites section and go ahead and set this up for the database. So what we need to do is run the queue table command within Laravel.
That's going to go ahead and generate a migration for us, which will create our queue table. So if we just have a look at this really quickly over in migrations, create jobs table.
Let's have a look at this. Contains everything Laravel needs to insert jobs onto this queue, which will be in the database. And then we'll be able to run them.
So now, of course, we just need to migrate our changes. So let's go ahead and say phpr to migrate. And that will have created out a jobs table. And every time a job gets put into here, it will be inserted.
Our queue worker will pick up on the job that needs to be run. It will be run. And of course, all of this is happening in the background, not at runtime while we are working through our app.
Now, the last thing that we need to do here, really importantly, is make sure that we have configured the queue driver or queue connection inside of our EMV file to actually use the database.
Sync is just like a normal app. It's just going to do it at runtime as this job is run. So we're going to switch this over to not date time, database. Great.
OK, so how do we run our queue? Well, we're going to need another tab open for this. So let's keep this one for any commands we run. And we're going to run phpr to queue work.
Now, once again, there are loads of options you can pass through to here. Queues are incredibly powerful in Laravel. But at least for now, we just want to run queue work.
That's it. And that's going to hang there and wait. So now what's going to happen is when a job goes into that database table,
this queue is going to work through each of them jobs that we have inside of here. Now, in the next episode, we are going to actually queue our endpoint checks.
So we'll see these roll in. And we will see them processed in here. What we're also going to need to do is set up our scheduler, our short schedule,
just so the jobs actually get put into the queue in the first place. Let's handle all that in the next episode. Now we have all of our queue stuff set up.
44 episodes4 hrs 59 mins


Ready to dive into Inertia? Let's build a real-world app with Laravel, Inertia and Vue! If you're already working with Inertia, you'll pick up some tips and techniques for future projects.

This uptime monitor allows you to create and switch between sites, then add endpoints to monitor with frequency intervals. Using the power of scheduling and queues, it'll automatically alert the email addresses you've added via the UI when an endpoint goes down.

In this course, you'll learn to:

  • Build a real app from scratch with Inertia
  • Work with Laravel queues
  • Perform actions on models at user-defined intervals
  • Work with sub-minute schedules in Laravel
  • Send out channel notifications with Laravel
  • Use API resources to simplify Inertia data
  • Organise apps with events and observers
  • Create modals in Vue
  • Perform inline editing with Inertia forms
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!


No comments, yet. Be the first to leave a comment.