I am migrating a NET6-based in-process function app to a NET7-based isolated function app. It uses Durable Functions, which have changed quite a bit in its API. I need to call an activity function that needs to be retried if the error message contains a keyword
.
Previously, with 5 retries, 5 mins apart, this was:
var retryOptionsOld = new RetryOptions(TimeSpan.FromMinutes(5), 5)
{
Handle = ex => ex.Message.Contains("KEYWORD")
};
await ctx.CallActivityWithRetryAsync("activityName", null, retryOptionsOld)
Now, we need to pass TaskOptions
to the activity function. However, I don't seem to be able to pass an error message condition AND a time limit condition at the same time. It seems that I can only do one or the other.
var retryOptionsNew1 = TaskOptions.FromRetryHandler(ctx => ctx.LastFailure.ErrorMessage.Contains("KEYWORD"));
var retryOptionsNew2 = TaskOptions.FromRetryPolicy(new RetryPolicy(5, TimeSpan.FromMinutes(5)));
await ctx.CallActivityAsync("activityName", null, retryOptionsNew1); //or...New2
How can I build something like before, combining time parameters and a handler condition?
You can use the constructor of TaskOptions
that takes the RetryPolicy
.
var retryPolicy= new RetryPolicy(
maxNumberOfAttempts: 3,
firstRetryInterval: TimeSpan.FromSeconds(5))
{
HandleAsync = c => Task.FromResult(c.Message.StartsWith("err"))
};
var taskOptions = new TaskOptions(retryPolicy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With