删除 SingletonAttribute 后无法在 Azure WebJob 中获取 Singleton 锁

Unable to acquire Singleton lock in Azure WebJob after removing SingletonAttribute

我有一个包含具有 TimeTriggerAttribute 的函数的 WebJob。它们上面还有一个 SingletonAttribute,所以它们不会并行执行。

在应用服务中部署一切正常。

当 运行 在本地时,它确实按预期工作了一段时间,然后作业主机报告的输出:

Development settings applied

Found the following functions:

MyNamespace.WebJobs.Functions.MyFunctionAsync

Unable to acquire Singleton lock (bd99766f202e4ac4ba230557b7180bd2/MyNamespace.WebJobs.Functions.MyFuncitonAsync.Listener).

我删除了单例属性,但消息一直显示。我还重新构建了项目并重新启动了机器。没有任何帮助。

我重命名了该函数,它又按预期进行了安排。现在我也可以重新添加 SingletonAttribute 并且一切都按预期工作。当我将其重命名为原来的名称时,错误又回来了。

我该怎么做才能再次从作业主机获取锁?

通过阅读this article I figured out that on top of the SingletonAttribute I did set, the TimeTriggerAttribute uses another one behind the scenes. Thank you Janley Zhang

默认情况下,主机 ID 在部署中保持不变。因此,当使用同一存储帐户的多个开发人员在本地执行代码时,他们将尝试获取相同的 blob 租约,并且只有第一个会成功。

我最终为每个开发人员使用了不同的主机 ID,例如

if (jobHostConfiguration.IsDevelopment)
{
    jobHostConfiguration.UseDevelopmentSettings();
    jobHostConfiguration.HostId = Environment.UserName.ToLowerInvariant();
}