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
21. Creating a job to perform a check

Episodes

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

Transcript

00:00
okay let's go ahead and create the job out here we're not going to queue this just yet we'll leave that till a little bit later but as long as we've got a job and this actually works we can deal with the queues uh later on so we're going to go ahead and make a job in here which will
00:13
actually perform the check so i'm going to call this perform endpoint check and let's go ahead and open that up that's going to be in the jobs folder so perform endpoint check okay so what we have here is implement should queue i'm just going to go ahead and get rid of that just so we can keep this nice and clean for now see this run without having to put this in our queue first of
00:33
all now here we have got a constructor which is useful because we can pass the actual endpoint into this job and then we've got a handle method which will go ahead and make the http request to the particular endpoint and then it will update the endpoint with the new next check this is really important because if we don't update the next check it is obviously going to
00:56
just keep checking every single time we run this under our schedule which is actually going to end up being every second so we do not want to make a request to an endpoint every second okay so let's go over to perform checks and first of all dispatch this job so it actually works to do this we just go ahead and reference the job so perform endpoint check and call the dispatch method and
01:19
into this we can just pass in any data we need into the constructor and that's going to be the endpoint for each of these that we get through that's as simple as it gets so over in the perform endpoints check let's go ahead and accept in the endpoint here like so and pull that namespace in and then down here we'll figure this one out now there's a couple of ways that we can do this
01:43
we can touch this and add on a certain amount of seconds but i prefer to be a little bit more explicit so i'm going to go ahead and specifically call update here updating the of course next check column here so to update this we're going to grab the current date and time and we're going to add a certain amount of seconds onto the current date and time and then when we
02:04
restore this back into the endpoint because we have that set up as a date and just to show you that here we have that here it will be transformed into a date time string now what the seconds that we want to add onto this well it's going to be the frequency of the endpoint that we're currently checking because it's always going to increment in batch in the frequency that we have so we just
02:29
want to reference the endpoint that we've passed in and go ahead and grab out the frequency for this and that is pretty much it so what we can now do is we can run through this and see this in action so if we go over here and just bring back that old date that we had obviously this next check is long overdue so both of these should be checked and then we should have the current
02:53
date and time set up for however many seconds or minutes into the future so let's go over and try this out so i'm going to go ahead and rerun the checks perform command and if we head over now watch these dates they have now changed to the current date and time plus 300 seconds so that is our job that is updating the next check let's move over to actually making the http request

Episode summary

In this episode, we dive into creating a job to actually perform our endpoint check. We start by setting up a new job class called PerformEndpointCheck inside the jobs folder. To keep things simple and test it out, we skip queueing for now and focus on making sure the job logic works as expected.

We set up the job so it takes an endpoint as a parameter in the constructor, which allows us to handle different endpoints dynamically. Then, inside the job's handler, we add the essential logic: updating the next_check column on the endpoint. This is important because we definitely don't want to keep checking endpoints every second (which is what would happen if we skipped this!), so we explicitly add the endpoint's frequency to the current timestamp and update the value. That way, the next check will be correctly scheduled.

Finally, we test out dispatching the job and see how the job properly updates the next check time for overdue endpoints. This gives us a great foundation, and in the next episode, we'll move on to actually making HTTP requests within our job.

Episode discussion

No comments, yet. Be the first!