Wednesday, 22 August 2012

Schedule an ASP page to run through task scheduler on Windows Azure

Follow the below steps to schedule a job(scheduling an asp page to run) to the task scheduler.
Step 1: Create a web role.
Step 2: Create a command file (*.cmd file).
Step 3: Include below code to the command file to schedule the task to the Task Scheduler automatically.
SCHTASKS /Create /SC DAILY /ST 02:15:00 /SD 12/12/2011 /TN Task_Name /TR “File/exe/task path to run” /RU SYSTEM /F /RL HIGHEST
Ex: SCHTASKS /Create /SC DAILY /ST 02:15:00 /SD 12/12/2011 /TN HelloWorldTest/TR “.\approot\ HelloWorldTest.vbs” /RU SYSTEM /F /RL HIGHEST
above code schedule task which execute  a vbscript file which internally calls the web page.
Note: More information on SCHTASKS command is available here
Step 4: Create a vbscript (*.vbs) file and include the following code.
set x=createobject(“microsoft.xmlhttp”)
x.Open ”GET”, ””, False
set x=nothing
Above code sample is calling to a wep page hosted on cloud.
Step 5: Include the below code to the servicedefinition file of the created azure project.
<WorkerRole name=”helloworld_workerrole” vmsize=”Small”>
      <Task taskType=”simple” executionContext=”elevated” commandLine=”helloworld.cmd”>
Above code will execute the command file whenever web role new instance will be created.
Step 5: Since this web role’s work is to schedule a job to the VM’s Task Scheduler we need not to go for more than one instance.
Step 6: Host the application to Windows Azure Platform.
Step 7: Confirm whether the job is schedule in VM’s task scheduler by logging remotely to the VM and open Task Scheduler.
Note: In this blog post I am explained a way to schedule a task automatically which calls a web page which can have a certain logic to perform some tasks.

No comments:

Post a Comment