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.
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,
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.
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.
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,
Job History Since our scheduler is running for every minute we can look for Job history. Now, please check the following 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.
- public class MessageController: ApiController
- {
- [HttpGet()]
- public object GetServerTime()
- {
- return DateTime.Now.ToLocalTime();
- }
-
-
- }
If you will check
History now
, you will come to know that scheduler is running successfully,
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.