Answered by:
Run background job in cloud service at specific interval of time everday (similar to mobile azure service scheduler)

Question
-
I have a scenario where I need to run a background job in azure cloud service which is exactly similar to mobile azure services scheduler which I am looking for in cloud service.
I need to get some data from azure sql database, create a csv report and mail it to client. This should happen everyday at some particular point of time in a day.
If its there please provide some samples
Saturday, December 13, 2014 4:39 PM
Answers
-
Hi,
As far as I know, you can use Azure Scheduler to do this too, you just need to expose an endpoint, and then call this endpoint in scheduler. Please see the videos below.
#http://channel9.msdn.com/Shows/Cloud+Cover/Episode-127-Windows-Azure-Scheduler
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Will ShaoMicrosoft employee Thursday, January 8, 2015 12:21 PM
Monday, December 15, 2014 7:49 AM -
Hi Sharathm1,
As you have specifically mentioned about the cloud services, there are two ways to do it
Option 1. Write a custom logic in your web role on run method which will be running continuously and will get executed after the time span which you provide.
Something like
public override void Run() { while (true) { //Custom logic //Make the thread sleep for e.g. 1 day Thread.Sleep(TimeSpan.FromDays(Convert.ToDouble(1))); } }
Option 2. Deploy a dedicated worker role and add above logic to it's on run method.Now about which one you want to use and when?
It all depends on the usage and needs. i.e. Option 1 is not very much recommended but few folks use it, just to save the cost and avoid spinning up a new worker role. This should be used only when the scheduled function is not CPU intensive and number of users accesing your web role instance are minimal.
The second is the most recommended way to do it - i.e. spin up a dedicated worker and you are done. it will not only provide you the ease of maintenance but also will avail a lot of infrastructure for you where in you can perform all other background CPU / Memory intensive tasks in future without affecting your web role instances.
Bhushan | http://www.passionatetechie.blogspot.com | http://twitter.com/BhushanGawale
- Edited by Bhushan Gawale Monday, December 15, 2014 10:07 AM
- Proposed as answer by Shirisha Paderu Tuesday, December 16, 2014 12:49 PM
- Marked as answer by Jambor yaoMicrosoft employee Friday, December 19, 2014 6:54 AM
Monday, December 15, 2014 10:06 AM
All replies
-
Hi,
This is the below code snippet I found which relates to your requirement from " How to run Background Tasks in ASP.NET "
using
System;
using
System.Threading;
using
System.Threading.Tasks;
namespace
WebBackgrounder.DemoWeb
{
public
class
SampleJob : Job
{
public
SampleJob(TimeSpan interval, TimeSpan timeout)
:
base
(
"Sample Job"
, interval, timeout)
{
}
public
override
Task Execute()
{
return
new
Task(() => Thread.Sleep(3000));
}
}
}
Hope this helps.
Regards,
Shirisha Paderu
- Proposed as answer by Shirisha Paderu Saturday, December 13, 2014 6:12 PM
Saturday, December 13, 2014 6:01 PM -
HI Shirisha Paderu,
How to we schedule the time like i want to run everyday at 12am something like mobile azure services scheduler...
Saturday, December 13, 2014 8:26 PM -
Hi,
As far as I know, you can use Azure Scheduler to do this too, you just need to expose an endpoint, and then call this endpoint in scheduler. Please see the videos below.
#http://channel9.msdn.com/Shows/Cloud+Cover/Episode-127-Windows-Azure-Scheduler
Best Regards,
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Marked as answer by Will ShaoMicrosoft employee Thursday, January 8, 2015 12:21 PM
Monday, December 15, 2014 7:49 AM -
Hi Sharathm1,
As you have specifically mentioned about the cloud services, there are two ways to do it
Option 1. Write a custom logic in your web role on run method which will be running continuously and will get executed after the time span which you provide.
Something like
public override void Run() { while (true) { //Custom logic //Make the thread sleep for e.g. 1 day Thread.Sleep(TimeSpan.FromDays(Convert.ToDouble(1))); } }
Option 2. Deploy a dedicated worker role and add above logic to it's on run method.Now about which one you want to use and when?
It all depends on the usage and needs. i.e. Option 1 is not very much recommended but few folks use it, just to save the cost and avoid spinning up a new worker role. This should be used only when the scheduled function is not CPU intensive and number of users accesing your web role instance are minimal.
The second is the most recommended way to do it - i.e. spin up a dedicated worker and you are done. it will not only provide you the ease of maintenance but also will avail a lot of infrastructure for you where in you can perform all other background CPU / Memory intensive tasks in future without affecting your web role instances.
Bhushan | http://www.passionatetechie.blogspot.com | http://twitter.com/BhushanGawale
- Edited by Bhushan Gawale Monday, December 15, 2014 10:07 AM
- Proposed as answer by Shirisha Paderu Tuesday, December 16, 2014 12:49 PM
- Marked as answer by Jambor yaoMicrosoft employee Friday, December 19, 2014 6:54 AM
Monday, December 15, 2014 10:06 AM