We have two deployments (Prod and Test) of Azure Webjob running with TimerTrigger. Both the web apps have single instance. According to this article, TimeTriggers use singleton locks to make sure no parallel invocation. These two instances use the same storage accounts. The issue we are facing is that only one of the deployments seem to acquire the lock while other is unable to acquire the lock. If we stop the first webjob the second acquires lock and starts processing and vice-versa.
Does the lock depend on storage accounts? How can we make sure that both these deployments have separate locking mechanism and run at the same time?
Use different storage accounts or set host
You're right, you have to use different storage accounts.
From the documentation:
If you look at the implementation of the locking mecanism (StorageScheduleMonitor.cs):
So based on @volodymyr-bilyachat answer, there are two possibilities:
Having separated storage accounts: makes sense if you have a storage account per environment (dev/staging/prod)
Specifying the HosId property of the JobHostConfiguration class:
Make sure that you have Always On enabled on your Web App if you use TimerTrigger.