Azure - how do I run a job that calls a function i

2020-02-11 09:06发布

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.

标签: azure
3条回答
爷、活的狠高调
2楼-- · 2020-02-11 09:16

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.

查看更多
Juvenile、少年°
3楼-- · 2020-02-11 09:24

A worker role runs constantly. In your worker role, you should:

  1. Check whether or not the function has been run this hour. If so, do nothing.
  2. If function has not been executed this hour, execute function.
  3. In function, invoke web service and do your dirty work.
查看更多
仙女界的扛把子
4楼-- · 2020-02-11 09:33

Check the SQL Azure Agent project and its references to a great articles by the SQL Azure Team.

查看更多
登录 后发表回答