tags:

views:

95

answers:

4

I am currently working on setting up a system for my company using a classic ASP on IIS setup that is relying on data from a 3rd party API. Problem is the API responds extremely slow and all it sends is a large XML file or all data. Simple enough fix is to request is once a day and setup a database to store this info and have the app use the db as a source instead of the API.

I wrote the database filler code in an ASP file and just need to make sure it gets run every day. What is the best way to do this? I am not really familiar with best practices here, should I just have scheduled tasks open iexplorer pointing to the URL that runs the scraper or is there some kind of way to do it via the command line. Mostly worried that I am trying to translate how I would do this in PHP on LAMP to ASP/WISA instead of looking at this as its own issue.

+1  A: 

You probably want to create a windows service that'll run in the background - hard to do this with just an ASP page.

Paddy
This would require you to implement the scheduling code yourself. It would be super easy to mess this up and have a busy loop rather than an idle loop and just eat CPU.
alumb
+3  A: 

The equivalent of cron on a windows computer is "Scheduled Tasks". The how-to for Windows XP is here: http://support.microsoft.com/kb/308569. Similar steps can be followed on most versions of windows.

If you put the data filtering code in an asp file, you can make a http request to that file using the following VBS script:

Const WinHttpVersion = "5.1"
Dim objWinHttp, strURL

' Request URL from 1st Command Line Argument.  This is
' a nice option so you can use the same file to
' schedule any number of differnet scripts.
strURL = WScript.Arguments(0)

' For more WinHTTP v5.0 info, go to Registry Editor to find out 
' the version of WinHttpRequest object.
Set objWinHttp = CreateObject("WinHttp.WinHttpRequest." & WinHttpVersion)

If IsObject(objWinHttp) Then
    objWinHttp.Open "GET", strURL
    objWinHttp.Send
    If objWinHttp.Status <> 200 Then
        Err.Raise 1, "HttpRequester", objWinHttp.ResponseText
    End If
    Set objWinHttp = Nothing
End If

If Err.Number <> 0 Then
    ' Something has gone wrong... do something about it...
End If

The call to this would look something like:

HttpRequester.vbs http://localhost/MyApp/loadData.asp
alumb
I'd want to set this up on our server, and I imagine this could easily be the first of many as far as "run daily utility" apps go -- any idea how hairy this is going to get if I keep going down this path
Andrew G. Johnson
@Andrew I'd produce one batch file for each application you are building, but it shouldn't be to bad. We have about 15 scheduled tasks running on one of our windows servers without any problems.
alumb
@Andrew - this kind of scripting is going to grow wildly out of control eventually. I had this happen on the server I manage. I ended up building a .Net WinForms app that has a window for each separate process and a background manager to allow the program to be called without interactivity from the command line (this way a human can run it and interact or it can be called from the scheduler and do its job).
Joel Etherton
+2  A: 

I would recommend against using a scripting call to accomplish this. This would be best done with a .Net console application called from the Task Scheduler.

Joel Etherton
yea. This is a good suggestion. If you are familiar with .Net console apps, this would be better than the script I provided.
alumb
A: 

It is trivial to call the ASP page at scheduled intervals. Just use a Windows port of wget or curl (you can use IE if you have to) and set up a scheduled task to load the page at the interval you desire.

No scripting will be required for this, just put the executable path as the process you want to run and the URL in the parameters field (plus some other switches, depending on which program you end up going with).

RedFilter