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
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!