Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

like image 962
Vantage Avatar asked Jul 20 '16 08:07

Vantage


3 Answers

It happened to me that I migrated the web jobs to a new app service and I was getting the same error. After looking at everything I figured out what it was:

Make sure no instance of the web job is running in Azure. That means, stop the web job in Azure. 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. You need to stop the web jobs explicitly.

Adding a verbose logging level helped me a lot.

config.Tracing.ConsoleLevel = System.Diagnostics.TraceLevel.Verbose;
like image 150
Francisco Goldenstein Avatar answered Nov 20 '22 12:11

Francisco Goldenstein


You can overwrite the host ID to something other than the default. This code snippet is for v3 of the WebJobs SDK, but there is a similar setting also for the 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
}
like image 3
D. Siemer Avatar answered Nov 20 '22 13:11

D. Siemer


If you have published your webjob already to Azure, make sure it is not running there when in the meantime trying to run it locally.

like image 2
RuudvK Avatar answered Nov 20 '22 13:11

RuudvK