A strange this is happening in one of my WebJobs and I cannot find what's wrong.
This WebJob is configured to use ServiceBusTrigger as soon as a message is received on a particular Service Bus Queue. This function has an execution time of minutes / hours, so I configured the JobHostConfiguration like this:
config.UseServiceBus(new ServiceBusConfiguration()
{
MessageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions()
{
MaxConcurrentCalls = 3,
AutoRenewTimeout = new TimeSpan(4, 0, 0),
AutoComplete = true
}
});
If I understood correctly, this would grant that each function:
- Is executed maximum three times per instance in parallel (one per each message)
- The lock, on the message, is kept for a maximum of 4 hours. This would avoid the messages to be requeued if the processing time is less than 4 hours.
- As soon as the function completes, the message is removed from the queue (even if it should be the default behavior).
These messages contains jobs that must be executed for different users. In order to be executed in parallalel for different users, but as a singleton for each user, inside the function I take a lease (different from each user) and I keep it for 60 seconds, renewing it every 30 seconds with a Task.
This seems to work: jobs are executed in parallel for different customer and same requests for same users are serialized.
Now, sometimes it happens that the WebJob stops triggering the function, even if the queue is full of messages. I don't understand why.
As soon as I restart that webjob, everything runs as before. Any ideas on why this happens?
What I noticed is that the App was (wrongly) stopped, even if the webjobs were running. Maybe that was the problem?