19

While this question is particular to Azure, I'm sure that it is a common situation for cloud computing in general.

I have a list of tasks that I need run at a certain time. With a window's server, I can use Task Scheduler and schedule my program to run at a certain time. I could go a step further and create a windows service that would run at a given interval and then execute the appropriate task.

Does anyone have a suggestion on the best approach is for a cloud computing environment?

I could create a worker role that polls the task list every second and then throws the appropriate task into a queue that is processed by another worker role.

I could create a worker role that would run once a day, grab all the tasks and submit them to a queue. The processor roles would then pull an item off the queue and process at the appropriate time.

Any other suggestions?

Charles
  • 50,943
  • 13
  • 104
  • 142

7 Answers7

9

You can set up a Service Bus Queue and use that as the scheduler.

Send messages into the queue by setting ScheduledEnqueueTimeUtc on the message to the desired time and the message will show up in the queue at that time. In the executing worker/web role you set up a receiver on that queue and that will then get the job as soon as the message shows up, i.e. the job is due.

The nice thing about that is that you can use this to balances jobs across multiple instances and since the timer is completely external to your app you don't have to store and resurrect and manage it. SB does all that for you.

One caveat: SB doesn't have facility to cancel scheduled messages.

Clemens Vasters
  • 2,666
  • 16
  • 28
  • Although I'm a fan of Hangfire (and I've also used Quartz.net in the past), I feel that sometimes we don't want (or can't have) persistent SQL storage just for having a simple scheduler. For simple scheduled jobs I've been using [this approach (Service Bus Queue with a message Scheduled for future)](https://github.com/Drizin/AzureServiceBusUtils). Queues can also be used for deduplicating messages so that in high-availability cluster (multiple active nodes) all nodes can be scheduling the next executions without the risk that the job runs more than once. – drizin Jun 15 '22 at 14:50
7

There are now a couple of options for doing this on Azure

Phil
  • 2,239
  • 3
  • 25
  • 26
1

Yo can try with the the four offerings:

  1. Azure Worker Roles (Cloud Service)
  2. Azure Scheduler service
  3. Azure Mobile Services scheduler
  4. Azure Websites Web Jobs

For more Information please follow the link Azure Schedule Tasks

cracker
  • 4,900
  • 3
  • 23
  • 41
1

Duplicate of: Recommend a C# Task Scheduling Library which recommends Quartz.Net. I have recently worked on a project that used this successfully under Windows.

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Thanks for the link. That looks like a great library. However, at this point, I'm interested in best practices and architectural approaches. –  Feb 20 '09 at 22:48
1

I realize this is old, but it's still a common question. I'm using Windows Task Scheduler on one of my Azure VMs. It's simple to implement and saves you from having to reinvent the wheel.

http://www.voiceoftech.com/swhitley/index.php/2011/07/windows-azure-task-scheduler/

swhitley
  • 21
  • 2
0

You can schedule tasks in Mobile Services.

Nice demo video, too.

Denis M. Kitchen
  • 1,142
  • 2
  • 14
  • 24
0

Have you considered using variable expiration dates of items on an Azure queue?

I came across a novel approach for scheduling that should work on Azure too. Using ASP.NET Cache item callbacks. Here.

Tristan Warner-Smith
  • 9,631
  • 6
  • 46
  • 75
  • 1
    How would this work for Azure -- you can't register for callback to notify that the queue item has expired, and polling and checking expiration will possibly miss items. – David Pfeffer Jan 28 '11 at 14:27