简体   繁体   中英

What is the difference between SingletonScope. Function & Host in Azure WebJob

What is the difference between SingletonScope? Function & Host in Azure WebJob?

I have Time trigger hosted in two regions in AKS. I want to ensure that only one instance runs every time.

All my instances are sharing the same storage account. Can I use one of the above settings to configure my scenario?

Difference between WebJob host and Azure function:

The host is a runtime container for functions. The Host listens for triggers and calls functions. In version 3.x, the host is an implementation of IHost . In version 2.x, you use the JobHost object.

You create a host instance in your code and write code to customize its behavior. This is a key difference between using the WebJobs SDK directly and using it indirectly through Azure Functions.

In Azure Functions, the service controls the host, and you can't customize the host by writing code. Azure Functions lets you customize host behavior through settings in the host.json file.

For more information, see Compare the WebJobs SDK and Azure Functions

What is Singleton?

The Singleton attribute ensures that only one instance of a function runs, even when there are multiple instances of the host web app. The Singleton attribute uses distributed locking to ensure that one instance runs.

As in below example, only a single instance of the ProcessImage function runs at any given time:

[Singleton]
public static async Task ProcessImage([BlobTrigger("images")] Stream image)
{
     // Process the image.

To learn more about how the SingletonMode.Function works see: https://github.com/Azure/azure-webjobs-sdk/blob/master/src/Microsoft.Azure.WebJobs/SingletonMode.cs

Further you can specify a scope expression/value on a singleton. The expression/value ensures that all executions of the function at a specific scope will be serialized.

Check this link for example: https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#scope-values

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM