With Azure WebApps I know I can make a WebJob a singleton by adding the "is_singleton": true
to the WebJob settings.job
file, and this works great if I have for example, 3 instances in a single WebApp deployment.
However - how can I publish to two WebApps (use case, two different regions) and make the WebJob run as a singleton and only on one of the deployments.
Example of desired behavior:
Sydney Deployment
Singapore Deployment
I know I can log in to the azure portal and disable the web job in one of the deployments, but is there a transform or change I can make to my publish profiles in visual studio to achieve the desired behavior automatically?
I'm currently deploying with Visual Studio 2015.
Actually there's a pretty handy Singleton attribute which may be useful in your use-case, take a look at this , excerpts below;
The WebJobs SDK facilitates common distributed locking scenarios via its SingletonAttribute. You can simply apply SingletonAttribute to a job function to ensure that all invocations of that function will be serialized, even across scaled out instances.
[Singleton]
public static async Task ProcessImage([BlobTrigger("images")] Stream image)
{
// Process the image
}
There's also an example of how you can scope the Singleton down to a region:
You can specify a scope expression/value on the Singleton which will ensure that all executions of the function at that scope will be serialized.
[Singleton("{Region}")]
public static async Task ProcessWorkItem([QueueTrigger("workitems")] WorkItem workItem)
{
// Process the work item
}
From the point of view of the sites, those are two completely independent sites and so the webjobs in them will be independent of each other. If you want to make them a singleton you'll have to add some custom logic.
Options include:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.