azureazure-webjobsazure-queues

Azure WebJobs - Singleton WebJob on user basis


I need to run, on a scheduled period, a job for different users (e.g. CRM synchronization). This synchronization is triggered by a message on a ServiceBus queue put by another function that is triggered by a TimerTrigger every 30 minutes.

Now what I'd need is to avoid that each user job is run multiple times in parallel, i.e. I would need to block the processing of the same job for the same user if the previous job is not completed.

Let's visualize like this:

How to avoid this?

Do I have to implement manually a logic for Azure Lease Blobs?

Thanks.


Solution

  • Use WebJob's [Singleton] attribute. That acts like a distributed lock. Underneath, it's implemented with blob leases. This is a method-level attribute. You can provide a "scope" which determines the granularity of the lock; and the scope can be based on binding data.

    See https://github.com/Azure/azure-webjobs-sdk/wiki/Singleton for more details.