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
Playing
31. Setting up queues

Episodes

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

Transcript

00:00
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
00:05
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
00:15
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.
00:26
They are sent into a queue. We run a queue worker, and then they are run in sequence. Now, queues are incredibly powerful,
00:33
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.
00:44
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.
00:53
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,
01:03
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.
01:13
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.
01:21
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.
01:30
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.
01:39
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.
01:48
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.
01:59
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.
02:09
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.
02:20
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.
02:31
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.
02:41
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.
02:50
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,
02:56
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.
03:05
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,
03:13
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

Overview

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!

Episode discussion

No comments, yet. Be the first!