azure - Azure Web 作业中的信号量

标签 azure azure-functions azure-webjobs

我想知道信号量(锁)是否可以在 Azure 函数中工作。 我不希望两个单独的网络作业同时运行。网络作业采用相同的应用服务计划。

这是我可以用信号量保证的吗? (因为这可以实现跨进程锁定?)

最佳答案

第一个问题:您谈论的是 Functions 和 WebJobs。是哪一个?

如果您的应用服务计划进行任何扩展,信号量将不起作用,因为两个实例可能会在两台不同的计算机上启动。好处是:(对于 WebJobs)有一个简单的解决方案。

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

In this example, only a single instance of the ProcessImage function will run at any given time. When the function is triggered by a new image being added to the images container, the runtime will first attempt to acquire the lock (blob lease). Once acquired, the lock is held (and the blob lease is renewed) for the duration of the function execution, ensuring no other instances will run. If another function instance is triggered while this function is running it will wait for the lock, periodically polling for it.

您可以在这里找到更多信息:Azure WebJobs SDK - Singleton

编辑:
如果您使用的是 Azure Functions:基于 TimerTrigger 运行的函数 seem to run as Singletons .

The timer trigger supports multi-instance scale-out. A single instance of a particular timer function is run across all instances.

关于azure - Azure Web 作业中的信号量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47280923/

相关文章:

wcf - 调试 Azure 云服务 Web 角色的最佳方法

Azure函数: clarifications about zip deployment and run from package file

c# - Azure Durable Functions - HostBuilder 的等效项在哪里?

.net-core - .NET Core 中的 Azure Web 作业

azure - 本地运行的 Azure webjob 上的环境变量解析

azure - SELECT VALUE COUNT(1) FROM (SELECT DISTINCT c.UserId FROM root c) AS t 不起作用

azure - Apache Spark 的 .Net UDF 必须可从 Azure Databricks Notebook 调用

azure - 如何使用 Azure 服务近乎实时地监听 GCP 发布/订阅

java - 如何使用 MSI 从 Spring Boot 应用程序连接到 Azure key 保管库以进行本地开发

azure - 使用azure webjobs,我如何传递计划任务的参数