Azure - how do I run a job that calls a function in the webservice every hour?

前端 未结 3 1308
孤独总比滥情好
孤独总比滥情好 2020-12-18 14:23

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

相关标签:
3条回答
  • 2020-12-18 15:20

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

    0 讨论(0)
  • 2020-12-18 15:27

    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.

    0 讨论(0)
  • 2020-12-18 15:27

    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.
    0 讨论(0)
提交回复
热议问题