Reputation: 139
Im using Microsoft Azure and have a webservice and a SQL Azure db, I want to run a function every hour but not sure how to go about doing this? I assume it has something to do with Azure Worker Roles, but not sure how to get the worker role to run and to call the webservice.
Upvotes: 2
Views: 3032
Reputation: 30903
Check the SQL Azure Agent project and its references to a great articles by the SQL Azure Team.
Upvotes: 0
Reputation: 71028
In the Run() method of either a Web Role or Worker Role, you could kick off a thread that sleeps until the top of the hour, wakes up, performs whatever task(s) you want, and goes back to sleep. Just remember that, when having multiple instances of a Web or Worker Role that's doing scheduling, you need to make sure only one of those instances is actually doing the scheduling. One way to accomplish that is to try leasing a blob, prior to starting the scheduler thread. If you lock it, go for it. If not, just recheck periodically. Eventually the instance that obtained the lock will release it when its instance recycles (which should happen at least once monthly).
Alternatively, you could place messages on a queue with visibilitytimeout
set to a specific # of seconds correlating to some hourly time period. Then, each of your Web or Worker instances can periodically poll the queue for tasks to work on. The messages you push into the queue won't be visible to queue-readers until the visibility timeout period is reached.
Upvotes: 6
Reputation: 47375
A worker role runs constantly. In your worker role, you should:
Upvotes: 2