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
20. Determining endpoints to check

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 the fun part where we actually get to start performing checks now to do this we're going to have a central console command which will use our next check date or and time and find out all of the endpoints in the app which need to be checked
00:18
so let's head over and just start to create this out we're not going to do anything with this we're just going to go ahead and make sure that we're getting these records right so we're going to go ahead and make a command here called perform checks and let's go ahead and open that up that's under console and commands and let's just fill out some of the information in here first of all so
00:37
let's just say checks perform we're going to need to reference this in our schedule because obviously we don't want to have to manually run this ourselves it's going to be scheduled on a very short schedule and let's go ahead and just give this a description so let's just say perform endpoint checks okay so to run this at the moment it just goes ahead and returns a success code
00:58
which is absolutely fine we are just going to use artisan so we're going to go ahead and say checks and perform there we go it doesn't do anything at the moment so to grab a list of the endpoints which need to be checked or are overdue to be checked it's actually pretty straightforward so let's go ahead and we don't actually need to assign this but let's go ahead and assign it now
01:21
just so we can grab a count from this we're of course going to use the endpoint model and we really just need a very simple where for next check and we just want to check where this is less than or equal to the current date and time so let's leave it at that for now and let's just go ahead and grab the count from this and just die dump on the count so i'm going to go ahead
01:46
and run this and sure enough we get two if we head over to the database here you can see that the next check here is already in the past if i were to go ahead and update this one to now and then go ahead and modify this to be just a few minutes or a couple of minutes into the future we would expect when we run this command again to only see one because we haven't got to the point
02:10
yet where this is less than the current date so really that is everything we need to do to grab the end points that we want to check now what we're not going to do is go ahead and start to iterate through these and just start to perform http checks we need to think a bit more deeply about this because we really want to put these into a queue to be run on a queue so we don't
02:34
slow everything down so what we're eventually going to get to the point where we do is because we get a collection back from here we can just say each and then go ahead and do something inside of here and that is going to be dispatching a job which we can put on our queue so why don't we go over to the next episode fill in this job and update the next check within that endpoint

Episode summary

In this episode, we're starting to actually perform checks on our endpoints! We kick things off by creating a new Artisan console command named checks:perform. This command is designed to gather all endpoints that are due for a check, based on their next_check timestamp.

We walk through scaffolding the command, add some basic descriptions, and make sure it'll be ready to run automatically on a schedule (no one wants to run this manually). For now, the command grabs all endpoints where the next_check value is less than or equal to the current datetime. We test this by running the command, checking that it grabs the expected number of endpoints due for checking, and confirm it updates as we modify the database.

Before actually doing the HTTP checks, we discuss a bit of design: instead of running checks immediately (which could slow things down), we'll eventually dispatch a job to a queue for each endpoint that needs checking. So, in this episode, we get the foundational logic in place to fetch the right endpoints and prepare for the job-dispatching part, which we'll tackle in the next episode!

Episode discussion

No comments, yet. Be the first!