CFSchedule Does Not Work Twice, Looking for ColdFusion Downtime Checking Script

1.7k Views Asked by At

I need some help with creating an automatic timing script with ColdFusion. Every 60 minutes I would like to see if a page on one of my servers (http://www.mysite.com/ALERT.cfm) is working or not.

If the page is down when it is checked, then it will check again in 5 minutes to see if the page is back up. If it is not back up, then I am sent an e-mail to [email protected]. If it is back up, then no action is required and we start the 60 minute cycle check again.

I now understand how to do one check, but not two.

So here is the CFschedule code I am using

<cfhttp url="http://example.com/testpagetocheck.cfm" method="get" >
<cfif cfhttp.statusCode neq "200 OK">
<cfschedule action = "update"
task = "TaskName" 
operation = "HTTPRequest"
url = "http://www.example.com/ALERT.cfm"
startDate = "#createdate(2012,4,01)#"
startTime = "08:00 AM"
interval = "3600"
requestTimeOut = "10">
</cfif>

So say I have 4 pages - the page I want to check to see if it is down or not (testpagetocheck.cfm), page1.cfm which has the above code, ALERT.cfm which has the cfmail to send me a message if testpagetocheck.cfm is down, and then page2.cfm has the above code again, but with an interval of "once" and a start time of 5 minutes from now.

Page1.cfm to alertMe.cfm works like a charm. I am sent a message of the page being down. Page 2.cfm to alertMe.cfm also works beautifully. It also sends me a message the page I am checking is down. But, when I try to go from page1.cfm to page 2.cfm to alertMe.cfm, it does not seem like the cfschedule on page2.cfm is running so I end up not getting any mail when the server is dowm.

Can anybody please tell me what I am doing wrong? I am using CF7

3

There are 3 best solutions below

1
On

I think the logic itself is wrong.

Actually you want to do two things:

  1. Create a schedule to keep requesting a page every while.
  2. that requested page (through the schedule) has to check if a certain website/page is down or not and take an action.

So first create a file to call it one time. That file - say - createSchedule.cfm its job is to create the schedule only. Just write the schedule creation code:

<cfschedule .... url="http://mysite.com/checksite.cfm" ... />

Then create the checker file checksite.cfm that will be requested every while (by the scheduled task). This file checksite.cfm should include the cfhttp call and the if check, like this:

<cfhttp url="http://mysite.com/thePageYouWantToCheck.cfm" method="get" >
<cfif cfhttp.statusCode neq "200 OK">
<!--- send the email here, or just include the Alert.cfm file that will do --->
</cfif>

Finally just call the file createSchedule.cfm to schedule a task to keep requesting checksite.cfm that will do cfhttp check and take an action.


If all these cfm files are running on one CFServer, then if server goes down. All of them won't work, I mean you will never get an alert. Bul will get the Alert only if error occurred on thePageYouWantToCheck.cfm or it was running on other CFServer, in this case even if CFServer goes down you should get the alert.

Now .. there are many websites that provide this service (Site Down Check). Some are paid and others are free. The best free I am using since long time is this: http://www.uptimerobot.com/ It is only free with very nice features, check it.

0
On
<cfschedule action = "update"
task = "TaskName" 
operation = "HTTPRequest"
url = "http://www.mysite.com/ALERT.cfm?call=2"
startDate = "#createdate(2012,4,01)#"
startTime = "08:00 AM"
interval = "3600"
requestTimeOut = "10">

While you are setting up schedule task in page pass parameter call=2 on that base you can put condition whether you need to emailed or not..

But I am really surprised you are calling CFM page to check CFM page is down. If coldfusion is down then your schedule task will never going to call and you will never receive email for that unless you are just checking for alert.cfm get timed out or other 500 error.

0
On

I had some trouble with this the first time I used cfschedule as well. When you run a cfschedule tag, this just creates the task if it does not exist / updates it if it does exist. After creating / updating the task you have to then do the following:

<cfschedule action="run" task="taskName">

This will make the task run when you have set it up to run. It's not the most intuitive thing as you expect that since it is set up that it will run when you set it up to do so.