简体   繁体   English

Azure WebJob无法获取singleton锁问题如何解决?

[英]How to resolve unable to acquire singleton lock issue in Azure WebJob?

I am getting unable to acquire singleton lock issue when I am running the application locally.当我在本地运行应用程序时,我无法获取 singleton 锁问题。 How may I resolve it?我该如何解决?

Below is my code下面是我的代码

static void Main()
    {
        JobHostConfiguration config = new`enter code here` JobHostConfiguration();
        config.UseTimers();
        AutoMapperManager.SetAutomapper();
        JobHost host = new JobHost(config);

        //Task.Factory.StartNew(() => host.Call(typeof(Functions).GetMethod("GetActionItemPullData")));
        config.Tracing.ConsoleLevel = TraceLevel.Verbose;
        host.RunAndBlock();
    }

Regards, Vantage问候,有利

It happened to me that I migrated the web jobs to a new app service and I was getting the same error.我碰巧将 Web 作业迁移到新的应用程序服务,但遇到了同样的错误。 After looking at everything I figured out what it was:在查看了所有内容后,我想出了它是什么:

Make sure no instance of the web job is running in Azure.确保没有 Web 作业的实例在 Azure 中运行。 That means, stop the web job in Azure.这意味着,停止 Azure 中的 Web 作业。 Even the local copy won't run if you are targeting the same storage account.如果您的目标是相同的存储帐户,即使是本地副本也不会运行。

Stopping the app service doesn't stop the web jobs.停止应用服务不会停止 Web 作业。 You need to stop the web jobs explicitly.您需要明确停止 Web 作业。

Adding a verbose logging level helped me a lot.添加详细的日志记录级别对我有很大帮助。

config.Tracing.ConsoleLevel = System.Diagnostics.TraceLevel.Verbose;

如果您已经将您的 webjob 发布到 Azure,请确保它没有在那里运行,同时尝试在本地运行它。

You can overwrite the host ID to something other than the default.您可以将主机 ID 覆盖为默认值以外的其他内容。 This code snippet is for v3 of the WebJobs SDK, but there is a similar setting also for the v2.此代码片段适用于 WebJobs SDK 的 v3,但 v2 也有类似的设置。 This solution even works, if multiple people work locally on the same project.如果多人在本地工作在同一个项目上,这个解决方案甚至有效。

builder.ConfigureWebJobs(context =>
{
  if (IsLocal)
  {
    context.UseHostId(Environment.UserName);
  }

  // other context operations
}
This is the better approach I found, just sharing with you =).

    [Conditional("DEBUG")]
    private static void DebugWebService(IWebJobsBuilder builder)
    {
        builder.UseHostId(Guid.NewGuid().ToString("N"));
    }

Edited to adjust as Zach suggested.按照扎克的建议进行编辑调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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