2

I have got a WebJob containing functions having a TimeTriggerAttribute. They also have a SingletonAttribute on them, so they don't get executed in parallel.

Deployed in the App Service everything works as expected.

When running it locally it did work as expected for a while and then the output of the Job host reports:

Development settings applied

Found the following functions:

MyNamespace.WebJobs.Functions.MyFunctionAsync

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

I removed the singleton attribute, but the message keeps showing. I also re-built the project and restarted the machine. Nothing helped.

I renamed the function and it was again scheduled as expected. Now I could also re-add the SingletonAttribute and everything worked as expected. When I rename it back to the original, the error comes back.

What can I do in order to be able to acquire the lock again from the Job host?

Community
  • 1
  • 1
D. Siemer
  • 158
  • 8
  • I have found an [article](https://stackoverflow.com/questions/40296109/azure-webjob-timer-trigger-does-not-fire) which has similar issue. You could also read this [article](https://github.com/Azure/azure-webjobs-sdk-extensions/wiki/TimerTrigger) to learn Singleton Locks in TimeTrigger. If the blob lease cannot be acquired, it generally means that another instance of that function is running, so the function is not started in the current host. You could check on your side. Or provide your code in question. – Janley Zhang Mar 22 '18 at 05:54

1 Answers1

4

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

The ID of the host is, by default, constant across deployments. So when multiple developers that use the same storage account execute the code locally, they would try to acquire the same blob lease and only the first would be successful.

I ended up using a distinct host ID for each developer, like

if (jobHostConfiguration.IsDevelopment)
{
    jobHostConfiguration.UseDevelopmentSettings();
    jobHostConfiguration.HostId = Environment.UserName.ToLowerInvariant();
}
D. Siemer
  • 158
  • 8