Search code examples
azurequeueazure-functionsazure-webjobs

Azure Webjob/function Retry count


In a webjob with a trigger on a blob, I want to manage my retry count, because I need to do something at the last retry count, if I do just a try-catch I will lose my retry mechanism, and I can't wait for message to go to poison, because in the blob triggers all the messages of all the jobs listening to blobs goes to the same queue and I can't know where the poison messages come until I read all the queue !

so any idea (if it is possible) to get this retry count?


Solution

  • You can control the maximum number of retries via the maxDequeueCount setting in the "queues" config. That affects blob functions is because behind the scenes a control queue is used for dispatching blobs to your functions.

    And the below is the sample code to configure queue, in there you will be able to configure the maxDequeueCount and the default number should be 5. Here is the doc link:Queue storage trigger configuration.

        static void Main()
    {
        var builder = new HostBuilder();
        builder.ConfigureWebJobs(b =>
        {
            b.AddAzureStorageCoreServices();
            b.AddAzureStorage(a => {
                a.BatchSize = 8;
                a.NewBatchThreshold = 4;
                a.MaxDequeueCount = 4;
                a.MaxPollingInterval = TimeSpan.FromSeconds(15);
            });
        });
        var host = builder.Build();
        using (host)
        {
    
            host.Run();
        }
    }