tags:

views:

237

answers:

7

Hi guys,

This is a question regarding best practices. I hope to get some advice from other developers.

I need a page on my website to be requested at least once every 30 minutes. What I am trying to achieve is a timer that runs code I have in the web application.

There are some websites that check if your website is up, but in reality those are not reliable.

Looking forward to your ideas.

+2  A: 

There is a firefox add on Reload Every

Could also use wget with cron or a scheduled task

You could also just write some code in a page load event where you check if > 30 minutes have passed since the last hit then run some chunk of code.

Ryu
+3  A: 

This problem has two parts:

  1. How do you request a page once?
  2. How do you run code periodically?

Once you break it down like that, it becomes simple to write a Console or Windows Forms application that can run the "request page once" code "periodically".

John Saunders
+3  A: 

Step 1

Write a .Net console application that makes a request to the page you want to hit.

Step 2

Use Windows Scheduler to execute your console application (i.e. your .exe) every 30 minutes.

A: 

First you can use Grease Monkey to inject your Timer function in the website and inject this code :

<script language="JavaScript">
// CREDITS:
// Automatic Page Refresher by Peter Gehrig and Urs Dudli
// Permission given to use the script provided that this notice remains as is.
// Additional scripts can be found at http://www.24fun.com & http://www.designerwiz.com
// [email protected]
// 8/30/2001

// IMPORTANT: 
// If you add this script to a script-library or script-archive 
// you have to add a link to http://www.24fun.com on the webpage 
// where this script will be running.

////////////////////////////////////////////////////////////////////////////
// CONFIGURATION STARTS HERE

// Configure refresh interval (in seconds)
var refreshinterval=5

// Shall the coundown be displayed inside your status bar? Say "yes" or "no" below:
var displaycountdown="yes"

// CONFIGURATION ENDS HERE
////////////////////////////////////////////////////////////////////////////

// Do not edit the code below
var starttime
var nowtime
var reloadseconds=0
var secondssinceloaded=0

function starttime() {
    starttime=new Date()
    starttime=starttime.getTime()
    countdown()
}

function countdown() {
    nowtime= new Date()
    nowtime=nowtime.getTime()
    secondssinceloaded=(nowtime-starttime)/1000
    reloadseconds=Math.round(refreshinterval-secondssinceloaded)
    if (refreshinterval>=secondssinceloaded) {
        var timer=setTimeout("countdown()",1000)
     if (displaycountdown=="yes") {
      window.status="Page refreshing in "+reloadseconds+ " seconds"
     }
    }
    else {
        clearTimeout(timer)
     window.location.reload(true)
    } 
}
window.onload=starttime
</script>
Braveyard
A: 

Check the transcript for stackoverflow podcast #15, search for heartbeat.asp

alexs
A: 

Take a look at Nagois, it can hit your web app every 30 seconds. If this is for monitoring, I recommend the The Holy Trinity of Web 2.0 Application Monitoring.

Michael Valenty
A: 

Stackoverflow does this... See the blog entry here: http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

Basically, the have a callback function that gets called when a cached object expires. This can run whatever code you want, if you want it to load a page, you could do that with an HttpWebRequest. However, I imagine you just need some code run, so you could do that directly in the function.

WildJoe
I liked this approach even though I knew about it, but was pretty much sceptical about its availability as a stable one, but since stackoverflow use it and t work fine, I think thats a validity test already :).
Laith