-
Short version: what is the behavior if CallActivityWithRetryAsync is used in concert with Task.WhenAll()? Does the task not return until all retries have been exhausted, even if one of the Activity calls in the middle throws an exception? That's my assumption (and the desired behavior), but want to confirm.... Longer TL:DR version: the code/pseudocode is something like this.... double costForCircuit = //call a suborchestrator to get the circuit cost and add the margin
List<Task> offerWriterTasks = new List<Task>();
foreach (customer on circuit)
{
// do some other stuff first, and then....
offerWriterTasks.Add(context.CallActivityAsync(nameof(OfferWriter), "params that don't matter for this question"));
}
try
{
await Task.WhenAll(offerWriterTasks);
}
catch (Exception e)
{
log.logerror("one of the tasks failed, but unfortunately I can't get to all of the exceptions because WhenAll is dumb :-) ");
}
foreach (var task in offerWriterTasks)
{
if (task.Status == TaskStatus.RanToCompletion)
{
// do some stuff with the 'successful task'
}
else
{
// log some details of the failure
}
} With the exception (no pun intended) of the fact that WhenAll is dumb and only gives you the last 'exception' thrown, even if multiple of the tasks throws an Exception, this code works like I want. The issue is that the API that is called by the "OfferWriter" activity function will sometimes fail with a transient Exception ("Bad gateway" HTTP error). When that happens, I want to automatically retry the call, because it typically works the second time. If I set some retryOptions and change the call to CallActivityWithRetryAsync, will the combination of CAWRA and Task.Whenall behave as I expect... i.e. the "task" doesn't return if the activity function fails with an exception within the retry count, but only if it exhausts the retries and still fails? And if that happens, will it bubble up that last Exception as it currently does with only one try? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
ugh, sorry for the code formatting, apparently I didn't do that very well... hopefully still understandable |
Beta Was this translation helpful? Give feedback.
-
TL/DR: Extended answer: The As far as the exception behavior of |
Beta Was this translation helpful? Give feedback.
TL/DR:
Task.WhenAll(...)
will behave as you expect - it won't fail unless you exhaust the retry count.Extended answer: The
Task
that gets returned bycontext.CallActivityWithRetryAsync(...)
will not complete until either the activity function call succeeds or the retry policy expires. This means that the orchestration will not observe any intermittent failures because the tasks it create that have retry policies will just keep running. It also means thatTask.WhenAll(...)
won't fail unless the retry count is exhausted.As far as the exception behavior of
Task.WhenAll(...)
, it should behave the same as it did before - theawait
implementation of C# will expose just the first exception. If…