azure - 锁定不同 Azure webjobs 的 C# 代码

标签 azure azure-webjobs azure-webjobssdk

我在 Azure 中运行 2 个不同的 Web 作业(一项是计划的,一项是连续的)。第一个 webjob 中的一段代码与第二个 webjob 中的一段代码发生冲突(代码不完全相同),我想防止它们并行运行。

我正在考虑在这里使用 blob 租赁。或者,正如我读到的here ,Azure Webjobs SDK 支持单例属性。是否可以将此属性应用于不同 webjob 中的方法并具有公共(public)作用域(或下面的公共(public)锁)。

你能想到任何替代方法吗?

最佳答案

Is it possible to apply this attribute on methods in different webjobs and have a common scope (or common lock underneath).

根据我的经验,使用blob lease是个好主意。 .

Blob Leases allow you to claim ownership to a Blob. Once you have the lease you can then update the Blob or delete the Blob without worrying about another process changing it underneath you.

<小时/>

Can you think of any alternative way ?

ETag也用于乐观并发控制。更多详情可以引用this .

string ETag (r/o) – this is an identifier for a specific version of a resource. This is used for web cache validation, and allows a client to make conditional requests. ETags are also used for optimistic concurrently control. For example, if you were reading a blob and saved the ETag, then did some other processing and came back to upload a new version of that blob, you could read the ETag again and check it against the prior value. If the ETag values match, then the file hasn’t changed and you can upload a new version of it. If the match fails, the storage service will return a 412 error (precondition failed).

关于azure - 锁定不同 Azure webjobs 的 C# 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47375449/

相关文章:

azure - 认知服务 : Language Understanding (LUIS) - phrase list features allowed per model cannot exceed the limit of 10

azure - 使用 Azure 中的 ODBC 驱动程序连接到外部数据库

azure - 如何将asp.net core web作业发布到azure应用程序服务

c# - Application Insights - 如何将自定义指标添加到您的请求信息中?

azure-webjobs - Azure Webjob 3.0 - 无法从计时器函数中的 appsettings.json 读取配置变量

c# - Azure WebJobs SDK 3,尝试添加 BlobTrigger 和相关连接字符串

powershell - 如何使用 Powershell 递归通过目录树查找文件

azure - 将特定值映射到 Azure 数据工厂中参数化复制事件中的列

Azure WebJob 悄然终止 - 任何日志中均无任何内容

azure - 为什么使用 WebJobsSdk.marker 文件从 Azure WebJob 获取访问错误?这个文件是什么?