Search code examples
azure-web-app-serviceazure-webjobsazure-webjobssdk

In Azure WebApps (former WebSites), can I get number of instances running?


I'm creating Azure WebJob for processing data in Azure Tables and need to use some synchronization of the processing when there are multiple instance of WebSite (i.e. WebSite is scaled out).

Can I get such information from the infrastructure (how many instances of WebApp is currently running)?


Solution

  • This blog post has information on getting the number of instances of an Azure Website - http://blog.amitapple.com/post/2014/03/access-specific-instance/

    Specifically for continuous WebJobs there is an api call that gives you the status of all instances of a specific WebJob, you need to use the api described here: https://github.com/projectkudu/kudu/wiki/WebJobs-API#get-a-specific-continuous-job-by-name

    https://{sitename}.scm.azurewebsites.net/api/continuouswebjobs/{jobname}

    And the property is called detailed_status.

    For both of these scenarios you'll need to authenticate the request.

    But if what you need is to have a lock between your website/webjob instances you can use the website's shared file system, since all instances access the same file system (d:\home\...) you can use file system locks to synchronize.

    Here is a sample usage from kudu: https://github.com/projectkudu/kudu/blob/master/Kudu.Core/Infrastructure/LockFile.cs