I am implementing wait and retry using jitter see below. In the example below the delay is same.
How can I make delay dynamic?
var delay = Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: 3);
var retryPolicy = Policy.Handle<FooException>().WaitAndRetryAsync(delay);
In my Project, I have Azure function https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
var configuration = builder.GetContext().Configuration;
builder.Services.RegisterService(configuration);
}
}
public static IHttpClientBuilder RegisterService(this IServiceCollection serviceCollection,IConfiguration configuration)
{
return serviceCollection.AddHttpClient<IService, Service()
.AddPolicyHandler(RetryPolicyHandler.GetRetryPolicy())
}
public static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy(IConfiguration configuration)
{
var delay =Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: 3);
return HttpPolicyExtensions.HandleTransientHttpError().WaitAndRetryAsync(delay);
}