Is there a well-known pattern to manage the ServiceUnavailable ? I'm NOT so happy with something like this
catch (CloudException e) when (System.Net.HttpStatusCode.ServiceUnavailable.Equals(e.Response?.StatusCode))
{
var howMuchWait = TimeSpan.FromMinutes(1);
if (e.Response.Headers.TryGetValue("Retry-After", out var hValue))
{
if(RetryConditionHeaderValue.TryParse(hValue.FirstOrDefault(), out var time) && time.Delta.HasValue)
{
howMuchWait = time.Delta.Value;
}
}
logger.LogWarning(() => $"Service Unavailable... Let him rest a bit, I will wait for {howMuchWait}.");
await Task.Delay(howMuchWait);
return indexEntities.Select(x => (string)x[indexKeyFieldName]).ToList();
}
This code simply delay the current call to it but does not prevent calls from other threads.
Now I'm implementing something different using a Stopwatch
and I would like to know if there is a well-known pattern.
NOTE: everything using the SDK.