Windows Azure Scheduler

I am going to write my second article here, recently we had a situation in our project. We wanted to send SMS to our customer before 2 hours and 24 hours of appointment, after a good research I found that Azure scheduler is the best possible way to do this operation.

Windows Azure Scheduler allow you to invoke actions – such as calling HTTP/S endpoints or posting a message to a storage queue on any schedule. With Scheduler, you create jobs in the cloud that reliably call services both inside and outside of Windows Azure and run those jobs on demand, on a regularly recurring schedule, or designate them for a future date.

This article will explain you how to create Job using Windows Azure Scheduler

New Job

In Windows Azure management portal click on New, search scheduler, click Scheduler and then press Create button. 

image

Give scheduler a name. Here we are using name GetMessage

Click on Job collection, give a name of your job collections. Here we are using name GetMessageJob here,

image

Once your Job collection is done we need to set what action we want to use for this scheduler.

You can select three Action Types: HTTP, HTTPS, and Storage Queue. Here, I’ve selected HTTP, which gives you four method types: GET, POST, PUT and DELETE. Although you can use these differently, these correspond to Read, Insert, Update, and Delete in most REST based APIs.

image

I created a custom website http://schedulerjobtesting.azurewebsites.net/ in windows azure portal, we will host our API here to test scheduler.

Once Job is configured now you can move to third step that is called Recurrence. Here you can setup it once or many time based on given options. If you notice the following screenshot I am starting this right now and this Job will run in every one minute. 

image

Once your options are filled correctly, you can click on create and it will deploy your Job at azure.

Job Information

Once your Job deployed successfully you can go to management portal and find our Job as shown below,

image

Job History

Since our scheduler is running for every minute we can look for Job history. Now, please check the following image,

image

If you notice scheduler failed because we did not hosted it yet. When you select one of the jobs you can click on History Details to get details about the exact response you received. Remember we created a website called http://schedulerjobtesting.azurewebsites.net/ and now we are going to host an API http://schedulerjobtesting.azurewebsites.net/api/Message/GetServertime/ to make it work.

Please use the following code and host it, you can consider any API and use it.
  1. public class MessageController: ApiController  
  2. {  
  3.     [HttpGet()]  
  4.     public object GetServerTime()   
  5.     {  
  6.         return DateTime.Now.ToLocalTime();  
  7.     }  
  8.   
  9.   
  10. }  
If you will check History now, you will come to know that scheduler is running successfully,

image

Conclusion:

In this article, I mentioned only HTTP GET; you can use post, scheduler for sending SMS, email, etc. This can be really useful if you have tasks that run every X days/month.