Since the release of the latest Microsoft.Azure.WebJobs assembly, it is now possible to setup the retry policy of an Azure Function through an attribute such as [FixedDelayRetry]
. I was very interested in this feature since I have a Blob Trigger Function, which retries five times by default when it fails, and I was not interested in the retry policy feature. I wanted the function to not retry when it fails, or only once.
So I have setup this attribute in my function as you can see below, and have indicated an amount of maximum one retry if the function fails :
public class Function1
{
private readonly IGremlinService _gremlinService;
private readonly TelemetryClient _telemetryClient;
public Function1(IGremlinService gremlinService, TelemetryConfiguration telemetryConfiguration)
{
this._gremlinService = gremlinService;
this._telemetryClient = new TelemetryClient(telemetryConfiguration);
}
[FunctionName(nameof(Function1))]
[FixedDelayRetry(1, "00:00:10")]
public async Task Run([BlobTrigger("files/{directory}/{name}.pdf", Connection = "AzureWebJobsStorage")] Stream myBlob, string name, ILogger logger)
{
try
{
//my lengthy code not related to the issue
}
}
}
When I try this code on my testing environment, with the Storage Emulator and my CosmosDb Emulator, it works perfectly fine, the function retries only once when it encounters an exception.
However, when I run my function on the Azure platform, instead of retrying only once when it fails, it retries... nine times. I setup the value of the maximum of retries to 5, and this time, the function retried 25 times. I have the feeling that, instead of retrying the amount of times specified in the attribute, the function multiplies that number to the default retry policy of 5. Below you can see my logs, where the function clearly retried 10 times :
What am I doing wrong ?
The function app retry policy is independent of any retries or resiliency that the trigger provides. The function retry policy will only layer on top of a trigger resilient retry. You can read about retry behaviour at here.
Since Azure Blob has maxDequeueCount set to 5 (read here) that’s why you see that your message is being retried multiple times.
To achieve the desired result you can define the maxDequeueCount property in host.json to 1.