Detailed Notes
It is time for us to take our Python and Django skills to building a full application. This is part two in a two-part series of tutorials where we build an application from scratch. This series will walk through all the steps required to build your own solution.
A Python/Django Site Monitor
The application we build is a web solution for monitoring web sites and API end points. We can configure the application to simply do a heartbeat check or validate the content returned. This second part of the series focuses on the back-end python code. This is the "guts" of doing the checks and scheduling them. The bulk of our tutorial covers the Django steps, but there is plenty of Python to learn as well.
Transcript Text
[Music] [Music] okay so we're gonna go into part two of our python django example um a couple weeks ago now a couple sessions back we got through part one it ended up being a little more complicated than uh we could handle in one session so i think we'll be able to do it in this one uh there may be a couple there are some additional things that we're not going to go as deep into that we'll probably do better just to be sort of standalone kinds of other areas that we may want to go into but the goal was to basically take things that we'd talked about in about django and python in a couple of prior sessions and roll them into a nice little application that we could build and work on and so that's uh that's what we're doing here now since it's been a while we're going to start out by we'll take a look at our app so far where we're at sort of where we left off last time around and then we're going to talk about django one of the key things here is taking the django piece that we saw for front end for being able to use it really is a really nice object relational mapping tool and and using it to do data management things like that and using it in a headless environment so you know flipping to the other side of doing a non something without a user interface in front of it and some of the little bits of things that you need to do there then we're going to focus on the back end process of our application and working through the various types of responses that we had there and so let's talk about what we had last time around the key to this application is this going to be it's a way to monitor sites and api endpoints we just want something that's just a nice application that allows us to take a look at you know sort of just have something that's occasionally checking you know like heartbeats or values or something like that to make sure that our our api is up if it's an api our website is up if it's up our page is returning what it's supposed to return if we've got a web page and we looked at this with two different focuses one would be really just more of a heartbeat or a ping and then uh the other is something where would be more like an api where we're actually we want to check a value you know return value we want to do something more than just say hey do we get a you know a response from a web a url essentially and um look at we had a front end that was our essentially our administration and reporting side of it so we could take a look at what's out there as far as um and we could add a site remove a site edit the settings for a site and then there's a back end that is that really is that heartbeat thing that periodically you know wait essentially you know wakes up runs through the checks that it needs to check and then updates everything so we can see how our sites are going uh let's see so let me i'll flip to this first if i've got it nope it wasn't on this one it is on this guy so this is roughly what we built um now we're gonna this is a sort of the new version of it so we're gonna talk about some of the changes have been made uh but essentially what we've got is we've got these various sites that we've added and we can see in some cases let me just do an edit on this in some cases we've got something where we're looking for a value and we've got a url that's actually sending some parameters and then we've got others where it's really just a ping like the developer nurse site we just go out there and we just say hey you know i'm gonna see is it alive and if it is then it's gonna give us a you know a success or not and normally we just see either you know there's a failure or the site is alive so let's flip back here so that's our front end now the back end obviously not as visually interesting or anything like that but what it's going to do is we've got for all these sites for each of these sites or addresses that we've built it's going to go through there it's going to see basically it's going to say hey do i need to run this do i need to do a check against it and then i'm either going to do a ping or make a call to that site based on the type of uh here basically the type of call that i'm doing and then i'm going to update to make sure that i've got that you know it's got the latest result and then we're actually going to talk a little bit about uh cron versus scheduler because we've got a couple of ways that we can do this and python itself uh is even you know more rudimentary than it's not even a django thing it's a python thing is they've got a built-in schedule tool that may work depending on how we want to do it may be the better approach for us so in setting up that script we talked a little we just very briefly touched on it last time around so this time i want to spend a little more time we're going to talk about the basics of the script setting up the getting the django settings into the script so that we can utilize all of that uh the models and basically the database connection pieces that django gives us for free since we've already got those in the django application we want to use those in our script and then we'll walk through you know some basic queries and a simple example of running the script what it looks like and what kinds of things are going to be going on with it so let's jump over to some code and let's start with let me blow this up a little bit bigger so actually i'll start with the just as a as a refresher so the models was very simple the database model is very simple we have sites so each one of those things those boxes we saw on the interface is a site and essentially it's just got what we saw you've got a name a description the url that you're trying to hit and then some information to keep track of you know what was the last result uh when did it last uh when was it last updated and then there's some lookup tables related to those so it's very simple data model and when we jump over to this pop-up thing that's driving me nuts let's see put that there um and so we're going to jump into our our back-end script now the first thing that we've got is the bringing in the django pieces and that's actually fairly straightforward it's not terribly complicated uh if you remember we set up here we have the set django's got a default settings file that it gives us and then we did make some you know some changes to it so that for example uh here we could use a mysql database as opposed to a sql white that they give us by default and then we connected it to our our database for this application and we want to use those same settings and so in a script it's actually pretty straightforward there's a a class that's called settings and so we can put in that we can pull import from django.conf and then it's it this import os os gives us operating system kinds of things that we can do some access to that and all we need to do is we're going to come in and we're going to grab we're going to set actually set the environment for the django settings we're going to set it equal to our uh our project and then our settings file and this project was called monitor and then and actually we can do this in any order we want to essentially just import but we import the django stuff all of its classes and functions we call django setup and boom we're off and running so if you wanted to utilize the stuff that you set up for django in a script then those five lines will get you there the only thing you'll have to do is just tweak it based on your application name and the settings file and then just make sure that it's you know you depend on where you run the script you may have to make sure that's properly in the path but that's all you need to do it's a couple lines of code and boom you get the whole infrastructure of django you know available to you which is key because that allows us to utilize all of those models that we use you know that we built out now we've got um we've got a couple different imports here that i'm going to i'll sort of touch on as we go uh one of them is datetime and pytz these are these are really the these are key python date related stuff for lack of a better term not to get too technical and what you do with those is you get the ability to work with dates date times uh do calculations and and differences diffs between those uh actually or if you want to call it more specifically as they do at deltas and uh you see right here is that we you can that pytz allows you to do it's basically python time zone it allows you to set a time zone so you have a context for your uh your times your date times and your times and that's pretty key so that you don't end up just everything going to um greenwich mean time so you can do it to you know match whatever your your local system time is now the first thing we're going to do let me make sure i want to do that yeah so we've got our we've got our basics set up we're connecting to django we've got some basic time stuff here so let's look at our ping uh luckily that is insanely easy to do because what we're going to do is we're just going to use in our case we're just going to use the operating system ping and we get that through platform when we import platform it's going to get us a um it tells us what operating system we're working on and then sub process allows us to actually call something basically it's just you know hey make a shell command and so all we need to do in this case for the ping is actually pretty easy we're going to send it in an address and then we're going to do either a dash c or dash in depending on whether it is a windows operating system or not and so then all we do is we just build out our command which the command is just you give it the command this is the operating system or the shell command so this is you know so we do ping we're going to send a parameter we send it a value and then we're going to send it the hostname in this case which looks like if you do this it would be ping dash in 1 and then i could do like https on developer newer dot com and i probably missed something there what did i mistype that oh i think it's because it's a dash one i bet that's it maybe not so i maybe whoops nope so i missed one there but basically what that does is it says and because i think i got that well that should be there it is i must have missed something oh i'm sorry not dash c i'm sorry n is for windows c is for not so whoops and basically all that does is it says ping it one time so go out check that one time and see if you can find it and apparently this one it doesn't like it right now and so all you do there is then you're just going to return whether that call was successful or not and so that's our ping so when we're doing over here we're trying to see like for this site is it alive then all we do and this is uh we call it heartbeat so we've got two different types we have ping as the heartbeat and then data return is gonna we're gonna do something more complicated than a ping and then all we need to do is set the time amount how often do we check and then we're off and running and so here we've got our ping and now let's look down here search up to the bottom here jump to the end in a little bit uh what we do is and this is a full script so there's a couple things we're going to come back to but right now for the pings we're going to call those heartbeats so we're going to call this check heartbeats and just note i guess that this is all you know an inline script so this is a function we've got the ping function we create check heartbeats function the check request function and then we're going to come down to the main part and we're going to check the the heartbeats check the requests and then there's some extra stuff down here that we're going to do that we will talk about later so let's talk about the heartbeats and since we're using the django models this is really easy to do all we're going to do is we're going to use the model so we're going to go to our sites which is where did i put models ah there we go so i'm gonna go into the sites and i'm gonna check everywhere that ping is equal to one because that means that i wanna try a ping and so i'm going to grab all of them and i'm going to filter it by ping id equals to 1. i'm going to go ahead and this is where i'm using that utc time i just want to get my you know what time is it now and i'm using this date time it's pretty straightforward it's just a today which is probably pretty familiar if you're dealing with date time stuff anywhere almost every library framework has either now or today or something like that and so that's we're going to do is we're going to take the today we localize it to because i'm on utc i'm going to localize it to that and that's equal to now and so i'm just going to walk through so i list i've got all my sites that were returned from this query and i'm going to walk through each one and i'm just going to say for each of the sites then i'm going to see if the last time i checked it is either empty or it's equal to or i'm sorry actually the last time i checked it plus whatever the frequency is and that was and the frequency is how often do i want to uh what is the period of time between checks so if it's every five minutes it would say when was the last check plus five minutes is that less than now so is that already passed if it's greater than that amount now then that's in the future so we basically say hey if we've never checked before then we're going to go ahead and check and if we have we just want to see where that time frame sits and if we do need to check it so if we don't we'll take that that's a short path we're just going to say we skipped it so we'll see that come out that we just skipped that site otherwise uh we're going to grab the host out of the um out of the data for that record and then we're going to ping it and um all we do we actually don't need for the ping which is where i had the problem before is i don't actually do the https colon backside backslash i'm going to do it without that and so then i'm going to get my ping and so that results i'm going to grab the result from the ping oh i'm sorry first i'm going to go to my various results and basically i either have it's either fail or the site is live and so i'm going to check i'm going to go grab my fail object because i'm actually getting result that's the result that i get back from ping is actually going to be potentially an object um and so if the oh i'm sorry it's not it's just a zero one but what i'm going to do is i'm going to say if it is a one so if it's true basically then i'm going to set it equal to the uh the live object and this again remember that we're dealing with uh we're dealing with the model the attributes are actually objects and not always uh not necessarily an id when you're working within the django world so i have a last result since it is here since it's a foreign key on lookup result although i can go in and just do it by id what i really want to do is do it by class so i'm just going to grab a lookup result value and shove it into last result and that's what i do here is i go in and i do look up results and i'm going to do a get where the code is equal to live and let me um let me switch gears just a second here and open up the admin side and so we see here is that i have um for my results there's four different things that are out there that i've got in that lookup table and i don't have an actual really that i'd care about i don't have an actual numeric id but i do have if you guys remember we have these unique codes so that's what i'm looking for i'm either going to grab the live code or the fail code and if the result i get back from the ping is true then it's live otherwise it's going to be fail and then all i need to do is i'm going to set the last result equal to whatever this result is i'm going to say that the last time i checked it was now because i just checked it and i saved that record and all of this i'm i'm utilizing through these three things i'm utilizing django's model stuff to allow me to quickly you know with a few lines of code be able to do all of that so now if we look let me open this up just a little bit so if i were to run this monitor this thing called monitor engine all i need to do is it's just a straight python script so i'm just going to do python and then i'm going to send it the script that i'm running so when i run it what we'll see is right now it's kicking out i'm going to see the results i'm sorry the the uh since i'm sending this command and let me see where did i run it here somewhere up here here we go so then what it is i'm going to see each of these pings so i'm pinging and i've got multiple sites you can see here that i've got multiple sites that i'm i'm doing checks against now i think this one and this one and this one i think i've got three three are just pings yeah there's a heart three are heartbeats and then two are gonna be uh looking at data returned and so if i look at those three developing or rb consulting in my time matters oops i'm going to see each of those when it's going to go out and try to hit those and so it's actually giving me here so let's see so this one is developmenture.com it does rb sns and it does my time and then it's going to come in and it's doing the others we're going to look at later now if i run it again up and actually since right now i've got it scheduled to keep running let me change that real quick pull this out okay and i'll come back to that in a minute so this time because none of these have uh the time hasn't passed for each of these then it's just going to skip each of those sites because i've already hit each of those up so in each of these cases we can see where uh the frequency was you know it hasn't been long enough for me to want to do a heartbeat again so this is where our general engine for the application is going to work is we're going to kick this thing off and let it just run regularly like for example every minute and if it runs every minute then when it runs it's either going to skip stuff or it's going to update some of these things and so we can see here like developing or it just updated again and then on our site on our front end we're going to see where each of these uh where we get our last update and so we can see for like example this one this rv consulting is more frequent apparently because it updated on 351 where the other ones did not and so that's our i think that's what i cover for this one so that'll go so for now that's our initial piece here i'm going to come back to this but i wanted to get us through the most general version of the application particularly the back end so we've talked about whoops uh yeah there we go so we've talked about ping and so that one was pretty straightforward we're just gonna we're just gonna hijack the operating system ping so you know it's already there why not now uh jen or python actually gives us a nice way to do our gets and posts and things like that so we're going to work on a get we're not going to get into posts and puts we probably could if we wanted to but it seems like that would be a little bit complicated you probably want something that's you're really not going to do that as a heartbeat for a site if you're doing puts in posts then you're probably updating data and although you can do that as a test i would think you probably would not want to so we're going to keep it simple for this this type of application and so we're going to now switch gears a little bit from the ping to get and then with git we're going to get a response and we're going to look at a class in python that allows us to to work with that fairly simply and straightforward so now so we did our heartbeats let me shrink this where is that at let's shrink that down a little bit so that was heartbeats that's going to go through everything that is looking at the heartbeat side but now the other option we have are requests and this is where we're going to actually be able to look at a value so for example we're going to have um in this case we're just hitting our our server which is this thing and we're going to hit it with an address that we want to actually see what is the result that's coming back and we're going to check this every five minutes now as an example i want to go look at that let's see create a window if i go hit that this is what i'm going to see normally got something very simple and i built this this and the other one i added two little test urls to my site so hb is just this heartbeat and this is something you may want to do for your site i've seen this a lot of times where instead of just essentially doing a ping to make sure something's available and you would you would use this a lot where you've got for example like maybe an api that you want to see if the back end is up and you've got a some mobile apps that are hitting it then maybe the first thing they want to do is do some sort of a status check against the api in general and so maybe you would have like a heartbeat call or something like that that sends you know something back it may be just something like hey i'm alive uh sometimes you'll see and you'll get this actually go out to some major apis and they actually have status pages and so they may break this down so it may be you know the site is responding and they may have uh you know front end is up back end is up um migration tools are up you know something back up is down you know something like that is that you may have actually something pretty complicated that you'd want to check against and so we just to sort of give a an example of that as opposed to having to build out you know walk through a little api example i just added these into this site so it's pretty easy for us to to play around with them for setting up stuff locally so i did hb and then i did this other one that's just m which takes two values and multiplies them and so that one uh here whoop let me go back here so what i did to test it is i'm just going to give it 3 times 6 and then the value should be 18 and this would be much more like a an api kind of call where i would do something like this and then i should get a value back so i've added those two in for us to play around with this second piece and so now let's take a look at that uh and just actually i guess just for clarity we'll just walk through those real quick uh let's see so heartbeat uh i think we've talked about this before but in both these cases all i'm doing is i'm just i'm not going to our normal normally what we're going to do is we're going to build some values out and we go to our html essentially our template pages so if i look at this page in the django world it's siteless so if you remember i've got this thing where i've got these content blocks and then i've got some html that i'm basically building based on that and in this case go back to [Music] go back to my views here we go in this case instead of rendering as we do with html i'm just going to build out a raw http response and we see that when i did the heartbeat is all i did is i just sent it a string and it kicked it back and uh in the multiplier i've got my two values and i just multiply those out now i can do something you know complicated i can do uh hello world and if i change that and go back to heartbeat then now i'm just sending it and it's just like you can see it's just raw html of course now if i do that and i run my monitor then i'm going to see here that heartbeat failed and this is something actually that we i'm going to talk about in a second but we did change this up a little bit we clean this up because last time these were just straight uh backgrounds so actually now i've got something that's a little more colorful we'll take a look at that in a second or a few minutes as it were and let me kill that so that doesn't just continue to run and now we so we can build our response and we can do whatever we want to uh as part of that response it's really nice for again we don't need to have a full-blown an actual api although we have looked at that in the past we can do something like this and just you know have some values some urls that we build rather quickly you know it's just hey this is what i want the arl to look like and then we can you know force a response out that doesn't have to be we don't even have to build our html page we can just do something just a straight response so let's go back to our our primary engine here now before uh if ping is equal to one uh and this is the ping id which i could have grabbed the uh ping value but i just kept it this is an example where we can send a class like we did here or i can just go in and say just directly you know i'm going to cut to the chase and i'm going to send an id and i know that my two ids and i'll look at those real quick so the ping types are either data returned or heartbeat heartbeat has an id of one you can barely see it there which technically i would never need to see i probably should do it by heartbeat code here like i did with my lookup result but i just wanted to show that's it's cleaner to use it by code and more uh resilient because if for some reason the actual id of that record changes then that would break it but i wanted to show that you can actually just directly instead of doing it by ping i can use an underscore id and then just send an id value across um let's see and so i oh here we go so check request before i did it where the id is equal to one this time so do the same thing i'm going to grab my sites where now instead of the heartbeat i'm doing the value i still use that now that i used it before so i get the current time stamp what is it today right now and then i'm going to watch through walk through each site and essentially the same thing i'm going to say hey if i haven't checked it or um well that's neat i used i didn't need i don't know why i doubled that up but there you go uh or if the last check was since uh was more recently than i want to do my uh period my period of checks then i'll skip it um i'm sorry or if it if it is within the frequency so if it's longer than the last frequency or it's empty i'm going to do something otherwise i'm just going to say skipped it which we saw before now before we had the ping this one's actually not much more complicated now here i've got some prints to show the result text and status code which i think we can see here so for the ones that we've seen so like here if you can see the latest one i did is it actually kicked out this was the text of the of the result and this is the http response and so i can check for thing because it could be like here it's a 200 but it could be a 400 a 401 a 500 you know all those other typical responses now i can if i want i can say that for these these uh value checks that i want to make sure that i do have a 200 plus a value but i'm keeping it pretty simple in this case and i'm just going to say that if it's not a 200 because we're just doing it basically it's either yes we're getting something or no we didn't um so one of the things we're going to do is first we're going to see well actually i sort of messed with this one a little bit but this one first we're going to see is the result here so i'm going to get result is the actual result by default i'm going to assume it's a fail otherwise if the desired result is equal to 3 and this is oops this is where i've got two different versions of this value check so it's either the simple response or the value response the simple response says is it a 200. the value response says i'm going to give you a value and i want to check against that and we see that uh let me go back to my admin and so here for heartbeat this is the value i'm checking against if i wanted it to just be a simple response then even though i have a value it's not going to care what that value is and so it allows us you know we've got a heartbeat which is a ping we've got a get which is the uh simple response and then we've got the value response that says not only am i going to do a http get a web get i'm also going to check a value that's returned hey rob good question yeah um go back to your other screen for a moment uh the listing screen yep this one no right there okay so i'm assuming there's a way in uh django to do this but uh is there a way that it based on your drop down will hide or show that desired value uh what do you mean it's so that oh oh so like if i do this it would either hide or show this yes and it's not actually uh that's actually at that point it's not a django thing it's really it would be a standard javascript thing so what i would do um and this it that does get a little bit tricky because i think this is uh let me go back to that that's a good side question uh if i go to the list i think i'm using a form um no i'm not uh let's see am i using a form no i'm not so what i would okay what you would do is you would okay so i get now so you update it here based on so it this would check ah yeah there it is okay so you got if code in there all right yeah i was trying to follow this earlier uh and you kind of went a little faster but i i see it now okay cool yeah so so what i could do yeah is and i don't think i had any of that built in but yes so i could do that and just say based on that value that these things are going to be visible or not um and yeah django doesn't give us anything special on that but it's it's actually it's now we're just down to you know standard uh web stuff at that point so good question right yeah yes so it kind of looks like it's a so the way django does the web displays it's kind of like a jsp or um you know the jstl tag precisely precisely is it's it's really there it add it gives you your um more like a template essentially and it gives you some you know like jsp or asp or any of those it gives you a way to do some tags but then the rest of it is your you know you're building it into your your page itself and you can build and then you can include um like here you know you can build um you can you include javascript as needed and it's just gonna yeah it's gonna spit out your html on the back end okay cool thanks that answer from the question good question all right so uh so back to that so we've got our two different things we're either going to say if my result and this is again that's a good example here of where while i can use my ids it is so much easier to read if i'm building it based on like a readable code value so desired result equals the three actually if we look here is going to be i think that's the value response yeah this value response so it would be easier if i was actually doing code i would at least see value or i could do it by the name so that's something much more developer friendly instead of what is almost effectively a magic number because it's like i don't know what a id3 is unless i go back and look at the database so while it may be a shortcut in a sense for me to do this as an id it really is not as good maintainability wise and it is a little i guess it is a little bit faster because i'm not grabbing that object so there is that there is a cost there but you could do some of this stuff where i don't have to you know i can actually get a couple of these objects and cache them off at the start but i digress so here we are either going to check the value in which case we've got the two things we can look at is we either have results status code which gives us the status code which is you know 200 400 401 500 501 or whatever we check against our status code and we can say if we're checking that we just say if it's a 200 then we're live that's what we're using for our evaluation otherwise we don't care what the status code we actually care what the text is that's sent and then we want to make sure that um oh and we want to make sure that that text is equal to the text that we say it should be in which case let's go back over here this is the text that we say it should be that is our desired value and then we go back the same thing we did with the paint is again it's like okay whatever the last result is is going to be either live or failed that based on what we got we're going to set our last check time to now and then we're going to save it and then we're off and running so now and this goes back to what we had before let me get rid of this guy real quick and so now what we're going to be able to see let me get that is that we're going to go through and we're going to check for where did i run that here so i ran it and i'm going to do it's going to do a ping it's going to do another ping it's going to do another ping and then it's going to come through it's going to walk through and do the heartbeats but since i've got no printouts based on that right now it's only going to tell me if it skips it so here if i run it again then we're going to see where i have my three pings and then i have my two others and it's going to run those but it skipped those because it caught them last time so let's take another step on our uh interface and talk about that a little bit and then i'm going to talk about this the python scheduler to just uh essentially to clean this up because right now the way we've got it you can see is i have to manually run this engine each time or create a cron job that mainly runs it you know each time and the interface that i'm showing you right now is not quite uh was not what we had so i want to talk a little bit about how i've uh updated this let's make sure yes everybody's running right now and so i'm going to do a page refresh on this page so that i don't have to do a you know force a refresh every time to see how my sights are doing i'm going to change some background colors and look a little bit about that in the um and how we can do that in css it's a little bit of a slide trip but you know just to show a nice easy way to do this from css and we're going to talk about scheduler uh the nice thing about scheduling we're going to see it's really easy it's very easy to set up it's really easy to create a job schedule the job and then run it and sleep as needed it's it's like cron but it's probably even easier to understand than kron so it makes it a really nice tool which is why i want to make sure i cover that within this application and it does sort of round out everything so when we're done today we'll have an application that we could you know spin up and run and set up some sites that we want to work with and we're we've got a little monitor app going so one of the first thing and this goes back a little bit to the question we just had is one of the things i want to do whoops with my site is make it so that this thing doesn't force me to do a refresh is i want to just do an auto refresh and this is not a new trick but one that i want to make sure that i mentioned everybody so this is my site list page this is site list sites goes to sitelist.html and if i want to do a refresh it is literally that simple is that you can tell your page to do a refresh you tell it how many seconds uh how frequently you want to do it and then you're off and running so if i want to do it every second then i can i'm gonna have to refresh it once so i get that new value and now you're actually gonna see maybe you can see here it's actually refreshing every second so if i go in and run my well actually and i can see here's the back end where i can see it's just making this call it keeps making this call and if i turn on the update then what i'm gonna see is now there's probably a couple yeah so like here it's already changed its time and if i wait for a minute or two it's gonna you know it's gonna pick that back up so let me turn that off so it's not doing it every 15 sec or every second because honestly um and actually i can do it every 30 because the frequency the most frequent check we have in our application is one minute so i'm going to do it every 30 seconds i'm going to do an update i could do it every minute but every 60 seconds but i may miss one so i figure i'll just do it every 30 seconds for now and it's a local app so it doesn't matter too much so in doing that and now uh it you know since it was updating every second it hit an update now it's going to update every 30 seconds and i'm going to see at some point i'm going to see these guys update so that's a refresh on the page another thing i want to do is be able to change these so i can see if something is up or down so let me actually um [Music] let me break a couple of these so i'm going to say 3 times 6 is 19 and i'm going to say hb i'm going to give it something else to check for so those two are going to start to fail on me and what i want to do is i can see let me go back here as right now i see green but what i want to do is be able to see you know have something that's red if something's down and i could change these colors to a lot of different things which basically is either going to be here it's either the normal one for that i've got for my style sheet or my class it's either site or site down that's just the two things either it's up or it's down now all of these right now are up at some point it's gonna check these two guys and they're gonna go down and the easiest way to do that of course is css which where did i put my css here we go and actually open site and site it's actually site up inside down so let's just do that let's see if i go back here oh i think i had it oh i'm sorry is i have that it's either side up or site down and then i think if i create a new one it's going to actually pick up um the site itself so if i create a new one so here i can see now these two are down because i broke those values if i add a site i'm just going to add a site real quick that is heartbeat if i just just do that oh and i want to do this minutes uh simple response there we go so here it hasn't checked it so i can see this guy actually is gonna be uh he's got no color so this means i've never checked it this means it's alive this means it's failed and so i've got three different statuses basically for a site right now that's uh based on color and so that is either site upside down or just the default site and we had already the default site that we had that thing built up and so all i do with site up is it's going to be i can essentially just copy and paste it and i'm just changing some colors so i can see here uh let's see that the background color i changed that over and if you see oh this one's not down but uh before the text was it was a light i had a gray with a black text um it's the the forward the primary color well when i flip it i want to change the text to white so it shows up in that that green or that red and so really all i have to do is change background color here and let's see whoops and so that's for site up site down i'm going to make it red and boom i'm you know i'm off and running as any one of these i can pick that up and so now we've got a little bit more um visual you know interface you get a little better user experience because now i'm seeing those colors in there and like i said again this is where if you do stuff following your standards you know throw some uh use your css classes like we did you know from the start we had uh wait on the site list from the start we had the site class so that we were able to do some styling on these and so once we've got that then you know we're essentially we're off and running now i do want to say that i think i had site and i think i had another one let's see if i look at site box i got a site hover yeah so i had hi site hover and uh you may have seen that that actually does a little bit of shading and what i can do is i can actually do that take that same thing actually i'm going to move this here and if i want to get my site hovers for those then i can do site up and site down i'm going to do the same thing and i did like a site yep and that's just a [Music] so i'm strange up here and i'm going to do the same thing for site up and oops and sight down and right now i can see that's nothing's nothing happens on my hover oh in this case because it's a css it's a static change and i need to restart my server so it's going to pick that back up and now i should see on a hover but you can't really see it i make sure i got that right set up hover hover side down hover side down hover and i think i did not oop let's make sure i've got that right i may not be refreshing it right oh because it's not gonna i needed my mistake i need to jump to a new window because it's already cached that so let me instead move to a private window so it doesn't hold it and this should pick that up do my login gotta enter my password right and so now you probably can i don't know how well you can see it but now it's gonna pick up my hovers here so all that real quickly through css which again goes back to just like one of those nice little things that says hey you know make sure where you can use css classes and it makes your one it makes your interfaces a little cleaner uh you don't have these like special you know fonts and other things that you need to do just drive it through classes and then when you want to change the look and feel quickly then you can do it here so if i wanted to do like real quick and say that i don't like red i'm gonna make it blue if it's down and then i come in let's see i'm not sure if it'll do it yeah and then i force a refresh and then boom i can change that you know in a matter of seconds quite literally and when you're dealing with changing requirements and things like that then i would say definitely do that so that you can handle uh it's amazing how helpful that is with a customer that's constantly changing their minds and you can actually can show them that almo you know live you can actually walk through and do a a joint session with them and say hey this is what it's going to look like and so that brings us to the last piece i want to talk about is the scheduler itself and so um one thing we did not do in the prior that we would have to do is pip3 pip is the if you remember it's the package manager for python and so what we need to do is we're going to have to add schedule so if we do pip 3 install schedule pip 3 being python 3's version of it in this case it's going to say that it's already satisfied if you run it it'll install it if you don't it'll say that it's not going to be able to find the schedule piece and that allows us to do import schedule so i'm going to move these back up to the top of the page here to sort of get all of my imports together oh let's see and so i didn't have time twice oh i did have time twice it's already had time here and actually dates not being used so i'm gonna get rid of that so i can clear that up so i have to do is import schedule and jump to the bottom here and schedule works off of jobs and so i'm going to define and i'm just going to call it job and now instead of here you can see where i had my heartbeats and my check requests that was my this was what i had as my main so what i'm now going to do instead is i'm going to say that my job is checking those two and it's going to print out job complete just so that every time i run the job i'm going to see that hey you know i ran the the job now i can either do it uh it's doing the you know so once i've defined what my job is what is the function i want to run schedule says allows me to say all right well every time period i can either say every one minute i could say every 60 seconds i can say every hour every 24 hours all i'm going to say is do job it's much like we've probably seen if you've done like multi-threaded stuff in the past or something like that you define something as we do here and then you say run it uh what schedule does it says run it every time frame run that thing and so it's going to schedule that uh it's going to go in and run it and then all i need to do is i have this little loop that says that if i've got something that needs to that is waiting to be run then uh it's gonna run it and so that's what does what schedule does is it basically cues it up and then i need to do run pending to say run everything that's pending so i could you know conceivably depending on how we do it i could have something like i could have a couple of different things that run you know maybe one every one minute every two minutes another one there's every five one runs every ten hours and then i could basically say well but worst case i only want to run any of those every five minutes and so what i would do is i can say run pending run every job that's out there that needs to be run and then sleep here is i'm going to say just you know since i don't want to keep seeing if something's pending then i'm going to just sleep for a minute and come back and check it so that right there i i created my job you know my thing i'm going to do and then schedule itself it's just a couple lines of code and i'm off and running now the way this script runs is it runs through it says okay first time i fire up i'm just going to go ahead and run these two functions up above which is basically the job so i could just now actually in the main part of the script instead of doing it this way i could just say here i could just say job so i'm going to define it and i'm going to run it and then i'm going to schedule it and i'm going to run anything that's pending i can do that or i can just say forget that i'm not even going to run it um then i'm just going to come through here i'm going to define it i'm going to cue it up and then i'm going to run it and so what we'll see here and we've seen this actually as we've been running through this today if i run let me do this let me clear that so it's a little easier to see when i run it um did i miss something there date time time has no attribute sleep so oh i'm sorry because i had a date time time but i also had up here it was just called import time itself was the one that it's a different time where was that uh there we go import time okay so that's what i thought it was my mistake there is actually i needed my i needed time itself because you can do the time function from date time but there's also the time library which can sometimes be a little bit complicated but the one allows me to do sleep uh let's see yeah so now i'm gonna come in here so what happens when you change stuff on the fly so now oh it's because i need to uh my mistake and because i have those two it's going to be whichever one i call last is going to be the problem i wonder if i'm using the date time time at all i think i'm actually good so i think i can actually get rid of that one let's see this is why usually you don't want to do it on the fly but let's see if this will work for me there we go okay so i've cued it up and now it's going to wait and then it's going to end up waking up and it's going to run the pending job now notice this time i didn't run it right away i could have which a lot of times is what you're going to do is you'll just say you know like here i would just come in and say hey job run it and then uh here it's just going to do while true so i don't have anything that is going to end this i can you know i'm basically going to have to either kill it or i can actually background it and let it run in the background and periodically it's going to show me the updates and i'll flip back to this in a second uh but that brings us to a point here where you sort of wrap it up a little bit and go to q a while i go flip back over there let me see is it run yet nope i hadn't run yet so using the ping and the request classes we talked about those we uh the those allow us to do that ping or a get we looked at some of this dynamic application of style so we had the the classes for up or down that we could see here you know we get those different colors we looked at the scheduler itself and then we looked at a page auto refresh and so with those um you know that gives us our back end a little bit of a clean up and now we've got a very simple uh little application that we could run you know however we want to do it i guess i probably shrink this down a little bit even we could have this thing running you know in the background somewhere either on our you know or we could have this actually it could be a nice little thing if you wanted to do a page essentially on your on your site whatever your site happens to be you could hook up a couple of these things and have it one of those you know status kinds of things that you typically see for example i think maybe aws status will have it yeah so you could see something like you could build something like this essentially and you could actually you could do this and tweak it uh for your specific site so that you could you know for your look so that you could have instead of the ui that i provided here you could do something like that that's that that basically lists it so that allows you a quick and easy way to do that let's see it ran i think so we can see here yes so it's it ran so we've got this scheduled thing it ran through but we also can see where it came back around and it skipped a bunch of those sites and then it just tells us job complete and then it just it's going to keep running in the background so now we have our back end running in the background we have our whoops our whoops that's our foreground let me kill that off anyways where did that go we have our foreground doing its every 30 second fresh refresh and so now we don't have to touch anything and it's going to tell us if a site goes down and there we go so questions and comments you know what interests me so much about and first off it great presentation and also lots of thoughts that come from it but what interests me so much is that you know we have the power as developers to really shure up a site in a way that most canned um canned you know whizzy wigs or whatever don't usually have you know right out of the box um i'm also thinking about this gives me so many ideas of shoring up you know the distributed architecture with different types of techniques you know pinging different services running messages through the the pipeline to kind of then intercept you know it going out of the the top of the funnel type thing um just to confirm everything's up and running that's that's really cool man appreciate it yeah it's a it's a really common thing that's out there that i don't think we usually don't think about it too much uh until something breaks and then you're like man i could have probably done something uh and this actually i mean i ended up building this concept of an app a long time ago because i just had a couple of sites and this was back when it was a lot harder to have a site that stayed up you know it's just more common something would happen to break a site and instead of me i sort of got in a habit of every day when i'd start my day i'd go walk through my three or four little sites to see if they were up and make sure that my website wasn't down and i said well that's sort of ridiculous and so what i did is i just you know built a little app that did it and you can do you could actually expand from this really easily and quickly you could do something like if the site goes down um you know if i do a check and the site's failed then i also send an email out that says hey your site's down you know i thought about adding that into this but it got it would have gotten a lot longer and you know we could have gotten a lot more complicated and i wanted to keep this a simple app but i think you can already see it there's a lot of things that you can do even with this to just have a you know a quick way to monitor what's up what's down and like i said it'd be really easy to add some notifications on top of it as well and it's it's just to me it's a good example of where within you know probably i don't know overall maybe an hour or two and you can have a full featured application using python and django that that has all of these pieces and you know you're ready to go so it's not and it's not even a like a prototype necessarily or something like that i mean it's a you've got a full app that you can run quickly you got a database behind it you've got tools to administer the data you know everything you possibly need so good other questions and comments this is really good rob i i like the quick and ease and the administration side of it because with the polling in that i could potentially write use this built the front end for my test generator tool so that you can build the test cases and actually run them from the gui instead of having to actually write the script yeah yeah well and actually um i think i don't i don't know if you know if you've seen this but that's actually one of the nice things and i may show this at some point because we did look at we did a little bit with python testing but it also with selenium which you've talked about uh it does allow us it has a python test uh export as well uh https developer oops i need one there there we go um that i can do let me just kick on it click on a couple of things real quick oh i'm not recording or am i yes i am recording so i can take you know i think this probably enough you've seen this before is i can take the normal stuff i do with selenium and it does have an export to python's pi test which is insanely i don't see that's in downloads i'll just show that real quick because i've actually been playing around with this lately for uh some scraping type stuff i did that made it so insanely easy using selenium stuff as you can see that it's actually you know it generates a real simple uh python script depending on how you do it and it uses the same stuff that you've seen i know that michael's talked about it you know extensively as far as the web drivers that are out there once you've got it uh python is a tool that has built up real has built a nice framework to work with that it's one of those just like java and c-sharp that you could do something much more complicated is i could actually use this i mean this is from scratch but i could and uses the pi test stuff but i could actually basically steal this code build a web driver and i could actually use that as part of my monitoring is i could get something you know pretty complicated um i can also like you said i mean i could i could build something that runs my test scripts and then reports it back somewhere and then just ping that you know periodically to see if the tests failed um or i could even return it yeah i can and i could add to it there's some other things i could do right now we just do pass or fail i could uh within this i could actually grab the value that's returned uh in these you know like in this case where i'm looking at what the value is this return oh let me save that save that off and i could actually do something to display that so i could actually have that display here you know maybe like last return value or something like that so you can you can do a lot quickly uh like i said and it does have it's that's why i like to this is an application as an example is it just gives you a nice starting point point where there's a lot of things that you could you can you know leap from this platform to excellent other questions and comments all right hearing none that brings us to the end yet again so as always appreciate the time the feedback the interaction um you know all of the the time that you spent i know that we we spend it you know it is self-focused and extent because we want to make ourselves better and our career better but it is uh all that time spent is also great as far as the group is concerned we get some you know having the comments and the discussions it helps all of us grow if you have any questions about this or any additional information as always email info developingware.com is out there we have the contact us form on developmentor.com we've got our youtube channel the easiest way to go out there is just youtube and just do if you do developpreneur it will get you to the developer nor uh channel we got a lot of stuff out there we've got literally i think we're up to like 200 videos or something like that right now and it's just like it's growing by leaps and bounds we're definitely over a hundred um and then the vimeo we still update that somewhat regularly most this the new stuff the most part is going to youtube but these classes uh the mentor sessions still show up on develop the developer nor channel on vimeo as well and then we'll eventually end up on youtube and of course we've got the building better developers podcast uh the easiest way to get to that is you know you can do your favorite podcatcher whatever it happens to be or if you've got alexa you can just say alexa enable building better developers and boom it will go out there and grab it for you get the latest uh episode of that as always our goal is making every developer better we appreciate the time you spend doing that and go out there and have yourself a great [Music] day [Music] you
Transcript Segments
[Music]
[Music]
okay
so we're gonna go into part two
of our python django example um a couple
weeks ago now a couple sessions back we
got through part one
it ended up being a little more
complicated than
uh we could handle in one session so i
think we'll be able to do it
in this one uh there may be a couple
there are some additional things that
we're not going to go as deep into that
we'll probably do better just to be sort
of standalone
kinds of other areas that we may want to
go into but
the goal was to basically take things
that we'd talked about
in about django and python in a couple
of prior
sessions and roll them into a nice
little application that we could build
and work on
and so that's uh that's what we're doing
here
now since it's been a while we're going
to start out by we'll take a look at our
app so far where
we're at sort of where we left off last
time around
and then we're going to talk about
django one of the key things here
is taking the django piece that we saw
for front end
for being able to use it really is a
really nice
object relational mapping tool and and
using it to do
data management things like that and
using it in a
headless environment so you know
flipping to the other side of doing a
non
something without a user interface in
front of it and some of the
little bits of things that you need to
do there
then we're going to focus on the back
end process of our application
and working through the various types of
responses that we had there
and so let's talk about what we had last
time around
the key to this application is this
going to be it's a way to
monitor sites and api endpoints we just
want something that's just a nice
application that allows us to take a
look at you know sort of just have
something that's
occasionally checking you know like
heartbeats or values or something like
that to make sure that our
our api is up if it's an api our website
is up if it's up
our page is returning what it's supposed
to return if we've got a web page
and we looked at this with two different
focuses one would be really just more of
a heartbeat or a ping
and then uh the other is something where
would be more like an api where we're
actually we want to
check a value you know return value we
want to do something more than just say
hey do we get a you know a response from
a web a url
essentially and um
look at we had a front end that was our
essentially our administration
and reporting side of it so we could
take a look at what's out there
as far as um and we could add a site
remove a site edit the settings for a
site
and then there's a back end that is that
really is that heartbeat thing that
periodically
you know wait essentially you know wakes
up
runs through the checks that it needs to
check and then updates everything so we
can see how our sites are going
uh let's see so let me i'll flip to this
first if i've got it nope it wasn't on
this one it is on this guy so this is
roughly what we built
um now we're gonna this is a sort of the
new version of it so we're gonna talk
about some of the changes have been made
uh but essentially what we've got is
we've got these various sites that we've
added
and we can see in some cases
let me just do an edit on this in some
cases we've got
something where we're looking for a
value and we've got a url that's
actually sending some parameters
and then we've got others where it's
really just a
ping like the developer nurse site we
just go out there and we just say hey
you know i'm gonna see is it alive and
if it is then it's gonna give us a
you know a success or not
and normally we just see either you know
there's a failure or the site is alive
so let's flip back here so that's our
front end
now the back end obviously not as
visually
interesting or anything like that but
what it's going to do is we've got for
all these sites
for each of these sites or addresses
that we've built
it's going to go through there it's
going to see basically it's going to say
hey do i need to run this do i need to
do a check against it
and then i'm either going to do a ping
or make a call to that site based on
the type of uh here basically
the type of call that i'm doing
and then i'm going to update to make
sure that i've got that you know it's
got the latest result
and then we're actually going to talk a
little bit about uh cron versus
scheduler because we've got a couple of
ways that we can do this
and python itself uh is even you know
more
rudimentary than it's not even a django
thing it's a python thing is they've got
a built-in schedule tool that may work
depending on how we want to do it may be
the better approach for us
so in setting up that script we talked a
little we just
very briefly touched on it last time
around
so this time i want to spend a little
more time we're going to talk about the
basics of the script
setting up the getting the django
settings into the script so that we can
utilize
all of that uh the models and
basically the database connection pieces
that django gives us for free
since we've already got those in the
django application we want to use those
in our script
and then we'll walk through you know
some basic queries and
a simple example of running the script
what it looks like and
what kinds of things are going to be
going on with it
so let's jump over to some code
and let's start with let me blow this up
a little bit bigger
so actually i'll start with the just as
a as a refresher so the models was very
simple the database model is very simple
we have sites
so each one of those things those boxes
we saw on the interface is a site
and essentially it's just got what we
saw you've got a name a description
the url that you're trying to hit and
then some information to keep track of
you know what was the last result
uh when did it last uh when was it last
updated
and then there's some lookup tables
related to those
so it's very simple data model
and when we jump over to this pop-up
thing that's driving me nuts let's see
put that there
um and so we're going to jump into our
our back-end script now the first thing
that we've got is the bringing in the
django
pieces and that's actually fairly
straightforward it's not
terribly complicated uh if you remember
we
set up here we have the set
django's got a default settings file
that it gives us and then we did make
some
you know some changes to it so that for
example
uh here we could use a mysql database as
opposed to a sql white that they
give us by default and then we connected
it to our
our database for this application
and we want to use those same settings
and so in a script
it's actually pretty straightforward
there's a a class
that's called settings and so we can put
in that we can pull
import from django.conf
and then it's it this import os os gives
us operating system
kinds of things that we can do some
access to that
and all we need to do is we're going to
come in and we're going to grab we're
going to set
actually set the environment for the
django settings
we're going to set it equal to our uh
our project and then our settings file
and this project was called monitor
and then and actually we can do this in
any order we want to essentially just
import but we import the django stuff
all of its classes and functions we call
django setup
and boom we're off and running so if you
wanted to utilize
the stuff that you set up for django
in a script then those five lines will
get you there
the only thing you'll have to do is just
tweak it based on your application name
and the settings file and then just make
sure that it's you know you
depend on where you run the script you
may have to
make sure that's properly in the path
but that's all you need to do it's a
couple lines of code
and boom you get the whole
infrastructure of django
you know available to you which is key
because that allows us to utilize all of
those models
that we use you know that we built out
now we've got um we've got a couple
different
imports here that i'm going to i'll sort
of touch on as we go
uh one of them is datetime and pytz
these are these are really the
these are key python date related
stuff for lack of a better term not to
get too technical
and what you do with those is you get
the ability to work with dates
date times uh do calculations and and
differences diffs between those uh
actually or
if you want to call it more specifically
as they do at deltas
and uh you see right here is that we you
can that pytz
allows you to do it's basically python
time zone it allows you to set a time
zone so you have a context
for your uh your times your date times
and your times
and that's pretty key so that you don't
end up just everything going to
um greenwich mean time so you can do it
to you know match whatever your your
local
system time is now the first thing we're
going to do
let me make sure i want to do that yeah
so we've got our we've got our basics
set up
we're connecting to django we've got
some basic time stuff here
so let's look at our ping uh
luckily that is insanely easy to do
because what we're going to do is we're
just going to use in our case we're just
going to use the operating system
ping and we get that
through platform when we import platform
it's going to get us a um it tells us
what operating system we're working on
and then sub process allows us to
actually call something
basically it's just you know hey make a
shell command
and so all we need to do in this case
for the ping is actually pretty easy
we're going to send it in
an address and then we're going to do
either a dash c or dash
in depending on whether it is a windows
operating system
or not and so then all we do is we just
build out our command
which the command is just you give it
the command this is the operating system
or the shell command so this is you know
so we do ping
we're going to send a parameter we send
it a value and then we're going to send
it
the hostname in this case which looks
like
if you do this it would be ping dash
in 1 and then i could do like https on
developer newer
dot com and i probably missed something
there
what did i mistype that oh i think it's
because it's a dash one
i bet that's it maybe not
so i maybe whoops nope so i missed one
there but basically what that does is it
says
and because i think i got that well that
should be
there it is i must have missed something
oh i'm sorry not dash c
i'm sorry n is for windows c is for not
so
whoops and basically all that does is it
says ping it one time
so go out check that one time and see if
you can find it
and apparently this one it doesn't like
it right now
and so all you do there is then you're
just going to return whether that call
was successful or not
and so that's our ping so when we're
doing over here
we're trying to see like for this site
is it alive
then all we do and this is uh we call it
heartbeat so we've got two different
types
we have ping as the heartbeat and then
data return is gonna
we're gonna do something more
complicated than a ping
and then all we need to do is set the
time amount how often do we check
and then we're off and running and so
here
we've got our ping and now let's look
down here search up to the bottom here
jump to the end in a little bit uh what
we do
is and this is a full script so there's
a couple things we're going to come back
to
but right now for the pings we're going
to call those heartbeats so we're going
to call this check heartbeats
and just note i guess that this is all
you know an inline script so this is a
function we've got the ping function
we create check heartbeats function the
check request function
and then we're going to come down to the
main part and we're going to check the
the heartbeats
check the requests and then there's some
extra stuff down here that we're going
to do that we will talk about later so
let's talk about the heartbeats
and since we're using the django
models this is really easy to do all
we're going to do
is we're going to use the model so we're
going to go to our sites
which is where did i put models
ah there we go so i'm gonna go into the
sites
and i'm gonna check everywhere that ping
is equal to one because that means that
i wanna try a ping
and so i'm going to grab all of them and
i'm going to filter it by ping id
equals to 1. i'm going to go ahead and
this is where i'm using that
utc time i just want to get my you know
what time is it now
and i'm using this date time it's pretty
straightforward
it's just a today which is probably
pretty
familiar if you're dealing with date
time stuff anywhere
almost every library framework has
either
now or today or something like that
and so that's we're going to do is we're
going to take the today we localize it
to
because i'm on utc i'm going to localize
it to that and that's equal to now
and so i'm just going to walk through so
i list i've got all my sites that were
returned
from this query and i'm going to walk
through each one and i'm just going to
say for each of the sites
then i'm going to see if the last time i
checked it
is either empty or
it's equal to or i'm sorry actually the
last time i checked it plus whatever the
frequency is
and that was and the frequency is how
often do i want to
uh what is the period of time between
checks so if it's every five minutes
it would say when was the last check
plus five minutes
is that less than now so is that already
passed
if it's greater than that amount now
then that's in the future
so we basically say hey if we've never
checked before then we're going to go
ahead and check
and if we have we just want to see where
that time frame sits
and if we do need to check it
so if we don't we'll take that that's a
short path we're just going to say we
skipped it so we'll see that
come out that we just skipped that site
otherwise
uh we're going to grab the host out of
the
um out of the data for that record
and then we're going to ping it and um
all we do we actually don't need for the
ping which is where i had the problem
before is i don't actually do the https
colon backside backslash i'm going to do
it without that
and so then i'm going to get my ping and
so that results
i'm going to grab the result from the
ping oh i'm sorry
first i'm going to go to my various
results and basically i either have
it's either fail or the site is live
and so i'm going to check i'm going to
go grab my fail
object because i'm actually getting
result that's
the result that i get back from ping is
actually going to be potentially an
object
um and so if the oh i'm sorry
it's not it's just a zero one but what
i'm going to do is i'm going to say if
it
is a one so if it's true basically
then i'm going to set it equal to the
uh the live object and this again
remember that we're dealing with
uh we're dealing with the model the
attributes are actually
objects and not always uh not
necessarily an id when you're working
within the django world
so i have a last result
since it is here since it's a foreign
key on lookup result
although i can go in and just do it by
id what i really want to do
is do it by class so i'm just going to
grab a lookup result
value and shove it into last result
and that's what i do here is i go in and
i do look up results
and i'm going to do a get where the code
is equal to
live and let me um
let me switch gears just a second here
and open up the admin side
and so we see here is that i have um
for my results there's four different
things that are out there that i've got
in that lookup table
and i don't have an actual really that
i'd care about i don't have an actual
numeric
id but i do have if you guys remember we
have these
unique codes so that's what i'm looking
for i'm either going to grab the live
code
or the fail code and if the result i get
back from the ping
is true then it's live otherwise
it's going to be fail and then all i
need to do
is i'm going to set the last result
equal to whatever this result is
i'm going to say that the last time i
checked it was now because i just
checked it
and i saved that record and all of this
i'm i'm utilizing
through these three things i'm utilizing
django's model stuff
to allow me to quickly you know with a
few lines of code be able to do all of
that
so now if we look let me open this up
just a little bit
so if i were to run this monitor this
thing called monitor engine all i need
to do is it's just a straight python
script
so i'm just going to do python and then
i'm going to send it the script that i'm
running
so when i run it what we'll see
is right now it's kicking out i'm going
to see the results
i'm sorry the the uh since i'm sending
this command
and let me see where did i run it here
somewhere up here here we go so then
what it is i'm going to see each of
these pings so i'm pinging and i've got
multiple sites
you can see here that i've got multiple
sites that i'm
i'm doing checks against now
i think this one and this one and this
one i think i've got three
three are just pings yeah there's a
heart three are heartbeats
and then two are gonna be uh looking at
data returned
and so if i look at those three
developing or rb consulting in my time
matters
oops i'm going to see each of those when
it's going to go out and try to hit
those
and so it's actually giving me here
so let's see so this one is
developmenture.com
it does rb sns and it does my time
and then it's going to come in and it's
doing the others we're going to look at
later
now if i run it again up and actually
since right now i've got it scheduled to
keep running let me change that real
quick
pull this out
okay and i'll come back to that in a
minute so this time
because none of these have uh the time
hasn't passed for each of these
then it's just going to skip each of
those sites because i've already
hit each of those up so in each of these
cases
we can see where uh the frequency was
you know
it hasn't been long enough for me to
want to do a heartbeat again
so this is where our general engine for
the application is going to work is
we're going to kick this thing off and
let it just run regularly
like for example every minute and if it
runs every minute
then when it runs it's either going to
skip stuff or
it's going to update some of these
things and so we can see here like
developing or it just updated again
and then on our site on our front end
we're going to see where each of these
uh where we get
our last update and so we can see for
like
example this one this rv consulting is
more frequent apparently because it
updated
on 351 where the other ones did not
and so that's our i think that's what i
cover for this one
so that'll go so for now that's our
initial piece here i'm going to come
back to this but i wanted to
get us through the most general version
of the application
particularly the back end
so we've talked about whoops uh yeah
there we go so we've talked about ping
and so that one was pretty
straightforward we're just gonna we're
just gonna hijack the operating system
ping
so you know it's already there why not
now uh jen or python actually gives us
a nice way to do our gets and posts and
things like that so we're going to work
on a get
we're not going to get into posts and
puts we probably could if we wanted to
but it seems like that would be
a little bit complicated you probably
want something that's you're really not
going to do that as a heartbeat for a
site if you're doing puts in posts
then you're probably updating data and
although you can do that as a test i
would think you probably would not want
to so we're going to keep it simple for
this
this type of application and so we're
going to
now switch gears a little bit from the
ping to get and then with git we're
going to get a response
and we're going to look at a class in
python that allows us to to work with
that fairly
simply and straightforward
so now so we did our heartbeats let me
shrink this where is that at let's
shrink that down a little bit
so that was heartbeats that's going to
go through everything that
is looking at the heartbeat side but now
the other option we have are requests
and this is where we're going to
actually be able to look at a value so
for example
we're going to have um in this case
we're just hitting our our server which
is this thing
and we're going to hit it with an
address that we want to actually see
what is the result that's coming back
and we're going to check this every five
minutes now as an example i want to go
look at that let's see
create a window if i go hit that this is
what i'm going to see
normally got something very simple and i
built this
this and the other one i added two
little
test urls to my site so
hb is just this heartbeat and this is
something you may want to do
for your site i've seen this a lot of
times where instead of just
essentially doing a ping to make sure
something's available
and you would you would use this a lot
where you've got
for example like maybe an api that you
want to see if the back end is
up and you've got a some mobile apps
that are hitting it then maybe the first
thing they want to do is do some sort of
a status check against the api
in general and so maybe you would have
like a heartbeat call or something like
that
that sends you know something back it
may be just something like hey i'm alive
uh sometimes you'll see and you'll get
this actually go out to some
major apis and they actually have status
pages
and so they may break this down so it
may be you know the site is responding
and they may have
uh you know front end is up back end is
up um migration
tools are up you know something back up
is down
you know something like that is that you
may have actually something pretty
complicated that you'd want to check
against
and so we just to sort of give a an
example of that
as opposed to having to build out you
know walk through a little api example
i just added these into this site so
it's pretty easy for us to
to play around with them for setting up
stuff locally
so i did hb and then i did this other
one that's just m which takes
two values and multiplies them and so
that one
uh here whoop let me go back here
so what i did to test it
is i'm just going to give it 3 times 6
and then the value should be 18 and this
would be much more like a
an api kind of call where i would do
something like this
and then i should get a value back
so i've added those two in for us to
play around with
this second piece and so now let's take
a look at that
uh and just actually i guess just for
clarity we'll just walk through those
real quick
uh let's see so heartbeat
uh i think we've talked about this
before but in both these cases all i'm
doing is i'm just i'm not going to our
normal
normally what we're going to do is we're
going to build some values out and we go
to our html
essentially our template pages so if i
look at
this page in the django world
it's siteless so if you remember i've
got this thing where i've got these
content blocks and then i've got some
html that i'm
basically building based on that
and in this case go back to
[Music]
go back to my views here we go
in this case instead of rendering
as we do with html i'm just going to
build out a raw
http response and we see that when i did
the heartbeat is all i did is i just
sent it a string
and it kicked it back and uh in the
multiplier
i've got my two values and i just
multiply those out
now i can do something you know
complicated i can do
uh hello world
and if i change that and go back to
heartbeat
then now i'm just sending it and it's
just like you can see
it's just raw html
of course now if i do that and i run my
monitor
then i'm going to see
here that heartbeat failed
and this is something actually that we
i'm going to talk about in a second but
we did change this up a little bit
we clean this up because last time these
were just straight
uh backgrounds so actually now i've got
something that's a little more
colorful we'll take a look at that in a
second or a few minutes as it were
and let me kill that so that doesn't
just continue to run
and now we so we can build our response
and we can do whatever we want to
uh as part of that response
it's really nice for again we don't need
to have a full-blown
an actual api although we have looked at
that in the past
we can do something like this and just
you know have some values some urls that
we build rather quickly
you know it's just hey this is what i
want the arl to look like and then we
can
you know force a response out that
doesn't have to be we don't even have to
build our html page
we can just do something just a straight
response
so let's go back to our
our primary engine here
now before uh if ping is equal to one
uh and this is the ping id which i could
have grabbed
the uh ping value but i just kept it
this is an example where we can send a
class
like we did here or i can just go in and
say
just directly you know i'm going to cut
to the chase and i'm going to send an id
and i know that my two ids and i'll look
at those real quick so
the ping types are either data returned
or heartbeat
heartbeat has an id of one you can
barely see it there
which technically i would never need to
see i probably should do it
by heartbeat code here like i did with
my lookup result but i just wanted to
show that's
it's cleaner to use it by code and more
uh
resilient because if for some reason the
actual id of that record changes
then that would break it but i wanted to
show that you can
actually just directly instead of doing
it by ping
i can use an underscore id and then just
send an id value across
um let's see and so i oh here we go
so check request before i did it where
the id is equal to one this time
so do the same thing i'm going to grab
my sites where
now instead of the heartbeat i'm doing
the value
i still use that now that i used it
before
so i get the current time stamp what is
it today right now
and then i'm going to watch through walk
through each site and essentially the
same thing i'm going to say hey if i
haven't checked it or
um well that's neat i used
i didn't need i don't know why i doubled
that up but there you go
uh or if the last check was
since uh was more recently than i want
to do my
uh period my period of checks then i'll
skip it
um i'm sorry or if it
if it is within the frequency so if it's
longer than the last frequency or
it's empty i'm going to do something
otherwise i'm just going to say skipped
it
which we saw before now before we had
the ping
this one's actually not much more
complicated
now here i've got some prints to show
the
result text and status code
which i think we can see here so
for the ones that we've seen so like
here if you can see the latest one i did
is it actually kicked out this was the
text of the
of the result and this is the http
response
and so i can check for thing because it
could be like here it's a 200 but it
could be a 400
a 401 a 500 you know all those other
typical responses now i can
if i want i can say that for
these these uh value checks that i want
to make sure that i do have a 200 plus
a value but i'm keeping it pretty simple
in this case
and i'm just going to say that if it's
not a 200
because we're just doing it basically
it's either yes we're getting something
or no we didn't
um so one of the things we're going to
do is first we're going to see
well actually i sort of messed with this
one a little bit but this one
first we're going to see is the result
here so i'm going to get result is the
actual result by default i'm going to
assume it's a fail
otherwise if the desired result is equal
to 3
and this is oops this is where i've got
two different versions of this value
check
so it's either the simple response or
the value response
the simple response says is it a 200.
the value response says i'm going to
give you a value
and i want to check against that
and we see that uh let me go back to my
admin
and so here for heartbeat
this is the value i'm checking against
if i wanted it to just be
a simple response then even though i
have a value it's not going to care what
that value is
and so it allows us you know we've got a
heartbeat which is a ping
we've got a get which is the uh simple
response and then we've got the value
response that says not only am i going
to do a
http get
a web get i'm also going to check a
value that's returned
hey rob good question yeah um go back to
your other screen for a moment
uh the listing screen yep this one no
right there okay
so i'm assuming there's a way in
uh django to do this but uh is there a
way that it
based on your drop down will hide or
show that
desired value uh
what do you mean it's so that
oh oh so like if i do this it would
either hide or show this
yes and it's not actually uh that's
actually at that point it's not a django
thing it's really it would be a standard
javascript thing
so what i would do um and this it
that does get a little bit tricky
because i think this is uh let me go
back to that
that's a good side question uh if i go
to the list i think i'm using a
form um
no i'm not uh let's see am i using a
form no i'm not so what i would okay
what you would do is you would okay so i
get now so you
update it here based on
so it this would check ah yeah there it
is okay so you got if code in there all
right
yeah i was trying to follow this earlier
uh
and you kind of went a little faster but
i i see it now okay
cool yeah so so what i could do yeah is
and i don't think i had any of that
built in but yes so i could do that and
just say based on that value that these
things are going to be
visible or not um and
yeah django doesn't give us anything
special on that but it's
it's actually it's now we're just down
to you know standard
uh web stuff at that point
so good question right yeah yes so it
kind of looks like it's a
so the way django does the web displays
it's kind of like a jsp
or um you know the jstl tag precisely
precisely is it's it's really there it
add
it gives you your um more like a
template
essentially and it gives you some you
know like jsp or
asp or any of those it gives you a way
to do some tags
but then the rest of it is your you know
you're building it into your
your page itself and you can build and
then you can include
um like here you know you can build
um you can you include javascript as
needed
and it's just gonna yeah it's gonna spit
out your html on the back end
okay cool thanks that answer from the
question good question
all right so
uh so back to that so we've got our two
different things we're either going to
say
if my result and this is again that's a
good example here
of where while i can use my ids it is so
much easier to read
if i'm building it based on like a
readable code value
so desired result equals the three
actually
if we look here is going to be i think
that's the value response
yeah this value response so it would be
easier if i was actually doing code i
would at least see value
or i could do it by the name so that's
something much more
developer friendly instead of what is
almost effectively a magic number
because it's like i don't know what a
id3 is unless i go back and look at the
database
so while it may be a shortcut in a sense
for me to do this as an id it really
is not as good maintainability wise
and it is a little i guess it is a
little bit faster because i'm not
grabbing that object
so there is that there is a cost there
but you could do some of this stuff
where
i don't have to you know i can actually
get a couple of these objects and cache
them off at the start
but i digress so here we are either
going to check the value
in which case we've got the two things
we can look at
is we either have results status code
which gives us the status code which is
you know 200 400 401 500 501 or whatever
we check against our status code and we
can say if we're checking that
we just say if it's a 200 then we're
live that's what we're using for
our evaluation otherwise we don't care
what the status code we actually care
what the text is that's sent
and then we want to make sure that um
oh and we want to make sure that that
text is equal to
the text that we say it should be in
which case
let's go back over here this is the text
that we say it should be that is our
desired value and then we go back the
same thing we did with the paint
is again it's like okay whatever the
last
result is is going to be either live or
failed that based on what we got
we're going to set our last check time
to now and then we're going to save it
and then we're off and running so now
and this goes back to what we
had before let me get rid of this guy
real quick
and so now what we're going to be able
to see
let me get that is that we're going to
go through and we're going to check
for where did i run that here so i ran
it
and i'm going to do it's going to do a
ping it's going to do another ping
it's going to do another ping and then
it's going to come through it's going to
walk through and do the heartbeats but
since i've got
no printouts based on that right now
it's only going to tell me if it skips
it
so here if i run it again
then we're going to see where i have my
three pings
and then i have my two others and it's
going to run those but it skipped those
because it
caught them last time
so let's take another step on our uh
interface and talk about that a little
bit and then i'm going to talk about
this the python scheduler
to just uh essentially to clean this up
because right now
the way we've got it you can see is i
have to manually run
this engine each time or create a cron
job that mainly runs it
you know each time and
the interface that i'm showing you right
now is not quite
uh was not what we had so i want to talk
a little bit about how i've
uh updated this let's make sure yes
everybody's
running right now and so i'm going to do
a page refresh
on this page so that i don't have to do
a you know force a refresh every time
to see how my sights are doing i'm going
to change some background colors and
look a little bit about that in the um
and how we can do that in css it's a
little bit of a slide trip but
you know just to show a nice easy way to
do this from css
and we're going to talk about scheduler
uh the nice thing about scheduling
we're going to see it's really easy
it's very easy to set up it's really
easy to create a job schedule the job
and then run it and sleep as needed it's
it's like cron but it's probably even
easier to understand than kron
so it makes it a really nice tool which
is why i want to make sure i cover that
within this application and it does sort
of round out everything so when we're
done
today we'll have an application that we
could you know spin up and run and
set up some sites that we want to work
with and we're we've got a little
monitor app going
so one of the first thing and this goes
back a little bit to the question we
just had
is one of the things i want to do whoops
with
my site is make it so that this thing
doesn't force me to do a refresh is i
want to just do an auto refresh and this
is not a new
trick but one that i want to make sure
that i mentioned
everybody so this is my site list
page this is site list
sites goes to sitelist.html
and if i want to do a refresh it is
literally
that simple is that you can tell your
page to do a refresh
you tell it how many seconds uh
how frequently you want to do it and
then you're off and running
so if i want to do it every second then
i can i'm gonna have to refresh it once
so i get that new value
and now you're actually gonna see maybe
you can see here it's actually
refreshing
every second so if i go in and run my
well actually and i can see here's the
back end where i can see it's just
making this call
it keeps making this call and
if i turn on the update
then what i'm gonna see is now there's
probably a couple yeah so like here
it's already changed its time and if i
wait for a minute or two
it's gonna you know it's gonna pick that
back up so let me turn that off so it's
not doing
it every 15 sec or every second because
honestly
um and actually i can do it every 30
because the frequency the most
frequent check we have in our
application is one minute
so i'm going to do it every 30 seconds
i'm going to do an update i could do it
every minute but
every 60 seconds but i may miss one so i
figure
i'll just do it every 30 seconds for now
and it's a local app so it doesn't
matter too much
so in doing that and now uh it
you know since it was updating every
second it hit an update
now it's going to update every 30
seconds
and i'm going to see at some point i'm
going to see these guys
update so that's a refresh on the page
another thing i want to do
is be able to change these so i can see
if something is up or down so let me
actually um
[Music]
let me break a couple of these so i'm
going to say 3 times 6 is 19
and i'm going to say hb i'm going to
give it something else
to check for so those two are going to
start to fail on me
and what i want to do is i can see let
me go back here as right now i see green
but what i want to do
is be able to see you know have
something that's red if something's down
and i could change these colors to a lot
of different
things which basically is either going
to be here it's either the normal one
for
that i've got for my style sheet or my
class it's either
site or site down that's just the two
things either it's up
or it's down now all of these right now
are up at some point it's gonna check
these two guys and they're gonna go down
and
the easiest way to do that of course is
css
which where did i put my css here we go
and actually open site and site it's
actually site up inside down so let's
just do
that
let's see if i go back here oh i think i
had it oh i'm sorry
is i have that it's either side up or
site down and then i think if i create a
new one it's going to actually pick up
um the site itself so if i create a new
one so here
i can see now these two are down because
i broke those values
if i add a site i'm just going to add a
site real quick
that is heartbeat
if i just just do that
oh and i want to do this
minutes
uh simple response there we go
so here it hasn't checked it so i can
see this guy
actually is gonna be uh he's got no
color
so this means i've never checked it this
means it's alive this means it's failed
and so i've got three different statuses
basically for
a site right now that's uh based on
color
and so that is either site upside down
or just the default site
and we had already the default site
that we had that thing built up and so
all i do
with site up is it's going to be i can
essentially just copy and paste it and
i'm just changing
some colors so i can see here uh let's
see that the
background color i changed that over
and if you see oh this one's not down
but uh before
the text was it was a light i had a gray
with a black text
um it's the the forward the primary
color
well when i flip it i want to change the
text to white so it shows up in that
that green or that red and so really all
i have to do is change background color
here
and let's see whoops and so that's for
site up
site down i'm going to make it red and
boom i'm
you know i'm off and running as any one
of these i can pick that up
and so now we've got a little bit more
um
visual you know interface you get a
little better user experience because
now i'm seeing
those colors in there and like i said
again this is where
if you do stuff following your standards
you know throw some uh
use your css classes like we did you
know from the start
we had uh wait on the site list from the
start we had the site
class so that we were able to do some
styling on these
and so once we've got that then you know
we're essentially we're off and running
now i do
want to say that i think i had site
and i think i had another one let's see
if i look at site
box i got a site hover yeah so i had hi
site hover and uh you may have seen that
that actually does
a little bit of shading and what i can
do is i can actually do that
take that same thing actually i'm going
to move this here
and if i want to get my site hovers for
those then i can do site up and site
down
i'm going to do the same thing and
i did like a site yep and that's just a
[Music]
so i'm strange up here and i'm going to
do the same thing for site up
and oops and sight down
and right now i can see that's nothing's
nothing happens on my hover
oh in this case because it's a css it's
a static change and i need to restart my
server so it's going to pick that back
up
and now i should see on a hover but you
can't really see it
i make sure i got that right set up
hover
hover side down hover side down hover
and i think i did not oop let's make
sure i've got that right i may not be
refreshing it right oh because it's not
gonna
i needed my mistake i need to jump to a
new
window because it's already cached that
so let me instead
move to a private window so it doesn't
hold it and this should
pick that up do my login
gotta enter my password right
and so now you probably can i don't know
how well you can see it
but now it's gonna pick up
my hovers here so all that real quickly
through
css which again goes back to just like
one of those nice little things that
says hey
you know make sure where you can use css
classes and it makes your
one it makes your interfaces a little
cleaner uh you don't have these like
special you know fonts and other things
that you need to do just drive it
through classes
and then when you want to change the
look and feel quickly then you can do it
here so if i wanted to do
like real quick and say that i don't
like
red i'm gonna make it blue
if it's down
and then i come in let's see i'm not
sure if it'll do it yeah and then i
force a refresh and then boom i can
change that
you know in a matter of seconds
quite literally and when you're dealing
with changing requirements and things
like that
then i would say definitely do that so
that you can handle
uh it's amazing how helpful that is with
a customer that's
constantly changing their minds and you
can actually can show them that almo you
know live you can actually walk through
and do a
a joint session with them and say hey
this is what it's going to look like
and so that brings us to the last piece
i want to talk about is the scheduler
itself
and so um one thing we did not do
in the prior that we would have to do is
pip3
pip is the if you remember it's the
package manager for python
and so what we need to do is we're going
to have to add schedule so if we do
pip 3 install schedule pip 3 being
python 3's version of it
in this case it's going to say that it's
already satisfied if you run it it'll
install it
if you don't it'll say that it's not
going to be able to find the schedule
piece
and that allows us to do import schedule
so i'm going to move these back up to
the top of the
page here to sort of get all of my
imports together
oh let's see and so i didn't have time
twice oh i did have time twice
it's already had time here and actually
dates not being used so i'm gonna get
rid of that so i can clear that up
so i have to do is import schedule and
jump to the bottom here
and schedule works off of jobs and so
i'm going to define and i'm just going
to call it job
and now instead of here you can see
where i had my heartbeats and my check
requests that was my this was what i had
as my main
so what i'm now going to do instead is
i'm going to say that my job
is checking those two and it's going to
print out
job complete just so that every time i
run the job i'm going to see that hey
you know i ran the the job
now i can either do it uh it's
doing the you know so once i've defined
what my job is what is the function i
want to run
schedule says allows me to say all right
well every time period i can either say
every one minute
i could say every 60 seconds i can say
every hour every 24 hours
all i'm going to say is do job it's much
like
we've probably seen if you've done like
multi-threaded stuff in the past or
something like that
you define something as we do here
and then you say run it uh what schedule
does it says
run it every time frame run that thing
and so it's going to schedule that uh
it's going to go in and run it
and then all i need to do is i have this
little loop
that says that if i've got something
that needs to that is
waiting to be run then
uh it's gonna run it and so that's what
does what schedule does is it basically
cues it up and then i need to do run
pending to say run everything that's
pending
so i could you know conceivably
depending on how we do it i could have
something like i could have a couple of
different things that run
you know maybe one every one minute
every two minutes another one there's
every five one runs every ten hours
and then i could basically say well but
worst case i only want to run
any of those every five minutes and so
what i would do is i can say run pending
run every job that's out there that
needs to be run
and then sleep here is i'm going to say
just
you know since i don't want to keep
seeing if something's pending
then i'm going to just sleep for a
minute
and come back and check it
so that right there
i i created my job you know my thing i'm
going to do and then schedule itself
it's just a couple lines of code and i'm
off and running
now the way this script runs is it runs
through it says okay
first time i fire up i'm just going to
go ahead and
run these two functions up above which
is basically the job
so i could just now actually in the main
part of the script instead of doing it
this way
i could just say here i could just say
job
so i'm going to define it and i'm going
to run it and then i'm going to schedule
it and i'm going to run anything that's
pending i can do that or i can just say
forget that i'm not even going to run it
um
then i'm just going to come through here
i'm going to define it i'm going to
cue it up and then i'm going to run it
and so what we'll see here and we've
seen this actually
as we've been running through this today
if i
run let me do this let me clear that so
it's a little easier to see
when i run it um
did i miss something there date time
time has no attribute sleep
so oh i'm sorry because i had
a date time time but i also had up here
it was just called import time itself
was the one that
it's a different time where was that
uh
there we go import time okay so that's
what i thought it was
my mistake there is actually
i needed my i needed time itself because
you can do the
time function from date time but
there's also the time library which can
sometimes be a little bit complicated
but the one allows me to do sleep
uh let's see yeah
so now i'm gonna come in here so what
happens when you change stuff on the fly
so now oh it's because i need to
uh my mistake and because i have those
two it's going to be whichever one i
call last is going to be the problem i
wonder if i'm using
the date time time at all
i think i'm actually good so i think i
can actually get rid of that one
let's see this is why usually you don't
want to do it on the fly but let's see
if this will work for me
there we go okay so i've cued it up and
now it's going to wait
and then it's going to end up waking up
and it's going to run
the pending job now notice this time i
didn't run it right away
i could have which a lot of times is
what you're going to do is you'll just
say
you know like here i would just come in
and say hey job
run it and then uh here it's just going
to do while true so i don't have
anything that is going to end this i can
you know i'm basically going to have to
either kill it
or i can actually background it and let
it run in the background and
periodically it's going to show me the
updates
and i'll flip back to this in a second
uh but that brings us to a point here
where you sort of wrap it up a little
bit
and go to q a while i go flip back over
there let me see is it run yet
nope i hadn't run yet so using the ping
and the request
classes we talked about those we uh
the those allow us to do that ping
or a get we looked at some of this
dynamic application of style so we had
the
the classes for up or down that we could
see
here you know we get those different
colors
we looked at the scheduler itself and
then we looked at a page
auto refresh and so with those um
you know that gives us our back end a
little bit of a clean up and now we've
got a very simple
uh little application that we could run
you know however we want to do it i
guess i probably shrink this down a
little bit even
we could have this thing running you
know in the background somewhere
either on our you know or we could have
this actually it could be a nice little
thing if you wanted to do
a page essentially on your on your site
whatever your site happens to be
you could hook up a couple of these
things and have it one of those you know
status kinds of things that you
typically see for example i think
maybe aws status will have it yeah
so you could see something like you
could build something like this
essentially and you could
actually you could do this and tweak it
uh for your specific
site so that you could you know for your
look so that you could have
instead of the ui that i provided here
you could do something like that that's
that that basically lists it
so that allows you a quick and easy way
to do that
let's see it ran i think so we can see
here yes so it's it ran so we've got
this scheduled thing
it ran through but we also can see where
it came back around
and it skipped a bunch of those sites
and then it just tells us job complete
and then it just it's going to keep
running in the background so now we have
our back end running in the background
we have our whoops our whoops that's our
foreground let me kill that off anyways
where did that go we have our foreground
doing its
every 30 second fresh refresh and so now
we don't have to touch anything
and it's going to tell us if a site goes
down
and there we go so questions and
comments
you know what interests me so much about
and
first off it great presentation and also
lots of thoughts that come from it but
what interests me so much is that you
know we have the power as developers to
really shure up a site in a way that
most
canned um canned you know whizzy wigs or
whatever
don't usually have you know right out of
the box um
i'm also thinking about this gives me so
many ideas of shoring up
you know the distributed architecture
with different types of techniques you
know
pinging different services running
messages through
the the pipeline to kind of then
intercept
you know it going out of the the top of
the funnel type thing um
just to confirm everything's up and
running that's that's really cool man
appreciate it yeah it's a it's a really
common
thing that's out there that i don't
think we usually don't think about it
too much
uh until something breaks and then
you're like man i could have probably
done something
uh and this actually i mean i ended up
building this
concept of an app a long time ago
because i just had a couple of sites
and this was back when it was a lot
harder to have a site that stayed up
you know it's just more common something
would happen to break a site
and instead of me i sort of got in a
habit
of every day when i'd start my day i'd
go walk through
my three or four little sites to see if
they were up
and make sure that my website wasn't
down and i said well that's sort of
ridiculous and so what i did is i just
you know built a little app that did it
and you can do you could actually expand
from this really easily
and quickly you could do something like
if the site goes down
um you know if i do a check and the
site's failed then i also send an email
out that says hey your site's down
you know i thought about adding that
into this but it got it would have
gotten a lot longer
and you know we could have gotten a lot
more complicated and i wanted to keep
this a simple app
but i think you can already see it
there's a lot of things that you can do
even with this to just have a you know a
quick way to monitor what's up what's
down
and like i said it'd be really easy to
add some notifications on top of it as
well
and it's it's just to me it's a good
example of where
within you know probably i don't know
overall maybe an hour or two
and you can have a full featured
application using python and django that
that has all of these pieces and you
know you're ready to go so it's not and
it's not even a
like a prototype necessarily or
something like that i mean it's a
you've got a full app that you can run
quickly you got a database behind it
you've got tools to administer the data
you know everything you possibly need so
good
other questions and comments this is
really good
rob i i like the quick and ease and the
administration side of it because
with the polling in that i could
potentially write use this
built the front end for my test
generator tool so that you can build
the test cases and actually run them
from the gui instead of having to
actually
write the script yeah
yeah well and actually um
i think i don't i don't know if you know
if you've seen this but that's
actually
one of the nice things and i may show
this at some point because we did look
at we did a little bit with python
testing
but it also with selenium which you've
talked about
uh it does allow us it has a python test
uh export as well
uh https developer oops i need one there
there we go um
that i can do let me just kick on it
click on a couple of things real quick
oh i'm not recording or am i yes i am
recording so i can take you know i think
this
probably enough you've seen this before
is i can take the normal
stuff i do with selenium and it does
have
an export to python's pi test
which is insanely i don't see that's in
downloads i'll just show that real quick
because i've actually been playing
around with this lately
for uh some scraping type stuff i did
that made it so insanely easy
using selenium stuff as you can see that
it's actually
you know it generates a real simple
uh python script depending on how you do
it and it uses the same stuff that
you've seen
i know that michael's talked about it
you know extensively as far as the web
drivers that are out there once you've
got it
uh python is a tool that has built up
real has built a nice framework to work
with that it's one of those just like
java and c-sharp
that you could do something
much more complicated is i could
actually use this i mean this is from
scratch but i could
and uses the pi test stuff but i could
actually basically steal
this code build a web driver and i could
actually use that
as part of my monitoring is i could get
something you know pretty complicated
um i can also like you said i mean i
could i could build something that runs
my test scripts and then reports it back
somewhere and then just ping that you
know periodically to see if the tests
failed um or i could even return it yeah
i can and i could add to it there's some
other things i could do right now we
just do pass or fail
i could uh within this i could actually
grab the value that's returned
uh in these you know like in this case
where i'm looking at what the value is
this return
oh let me save that save that off
and i could actually do something to
display that so i could actually have
that
display here you know maybe like last
return value or something like that so
you can
you can do a lot quickly uh like i said
and it does have it's
that's why i like to this is an
application as an example is it just
gives you a nice starting point
point where there's a lot of things that
you could you can you know
leap from this platform to
excellent other questions and comments
all right hearing none that brings us to
the end yet again
so as always appreciate the time the
feedback the interaction
um you know all of the the time that you
spent i know that we we spend it
you know it is self-focused and extent
because we want to
make ourselves better and our career
better but it is uh
all that time spent is also great as far
as the group is concerned we get some
you know having the comments and the
discussions it helps all of us
grow if you have any questions about
this or any additional information
as always email info developingware.com
is out there
we have the contact us form on
developmentor.com
we've got our youtube channel the
easiest way to go out there is just
youtube and just do if you do
developpreneur it will get you to the
developer nor
uh channel we got a lot of stuff out
there we've got literally
i think we're up to like 200 videos or
something like that right now and it's
just like it's growing by leaps and
bounds we're definitely over a hundred
um and then the vimeo we still update
that
somewhat regularly most this the new
stuff the most part is going to youtube
but
these classes uh the mentor sessions
still show up on develop
the developer nor channel on vimeo as
well and then we'll eventually end up on
youtube
and of course we've got the building
better developers podcast uh the easiest
way to get to that is
you know you can do your favorite
podcatcher whatever it happens to be
or if you've got alexa you can just say
alexa enable building better developers
and boom it will go out there and grab
it for you get the latest
uh episode of that as always our goal is
making every developer better
we appreciate the time you spend doing
that and
go out there and have yourself a great
[Music]
day
[Music]
you