gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:02:44 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com