private CancelRetryHandler EnsureAutoRestRetryPolicy <T>(Microsoft.Rest.ServiceClient <T> client) where T : Microsoft.Rest.ServiceClient <T> { var handler = client.HttpMessageHandlers.First(h => h is CancelRetryHandler) as CancelRetryHandler; handler.WaitInterval = TimeSpan.Zero; return(handler); }
/// <summary> /// Set max retry times of retry after handler that is used to handle the response with retry-after header /// from environement variable AZURE_PS_HTTP_MAX_RETRIES_FOR_429 /// </summary> /// <returns>Whether succeed to set max retry times or not</returns> public static bool TrySetMaxTimesForRetryAfterHandler <TClient>(this Microsoft.Rest.ServiceClient <TClient> serviceClient) where TClient : Microsoft.Rest.ServiceClient <TClient> { int?maxretriesfor429 = HttpRetryTimes.AzurePsHttpMaxRetriesFor429; if (maxretriesfor429 != null && maxretriesfor429 >= 0) { return(serviceClient.SetMaxTimesForRetryAfterHandler(Convert.ToUInt32(maxretriesfor429))); } return(false); }
private static bool SetMaxTimesForRetryAfterHandler <TClient>(this Microsoft.Rest.ServiceClient <TClient> serviceClient, uint retrytimes) where TClient : Microsoft.Rest.ServiceClient <TClient> { bool findRetryHandler = false; foreach (var handler in serviceClient.HttpMessageHandlers) { var retryHandler = handler as Microsoft.Rest.RetryAfterDelegatingHandler; if (retryHandler != null) { retryHandler.MaxRetries = Convert.ToInt32(retrytimes); findRetryHandler = true; } } return(findRetryHandler); }
/// <summary> /// Set retry count of retry policy using ExponentialBackoffRetryStrategy from environement variable AZURE_PS_HTTP_MAX_RETRIES /// </summary> /// <returns>Whether succeed to set retry count or not</returns> public static bool TrySetRetryCountofRetryPolicy <TClient>(this Microsoft.Rest.ServiceClient <TClient> serviceClient) where TClient : Microsoft.Rest.ServiceClient <TClient> { int?maxretries = ServiceClientExtension.HttpRetryTimes.AzurePsHttpMaxRetries; if (maxretries != null && maxretries >= 0) { TimeSpan defaultBackoffDelta = new TimeSpan(0, 0, 10); TimeSpan defaultMaxBackoff = new TimeSpan(0, 0, 10); TimeSpan defaultMinBackoff = new TimeSpan(0, 0, 1); var retryStrategy = new ExponentialBackoffRetryStrategy( (int)maxretries, defaultBackoffDelta, defaultMaxBackoff, defaultMinBackoff); var retryPolicy = new RetryPolicy <HttpStatusCodeErrorDetectionStrategy>(retryStrategy); serviceClient.SetRetryPolicy(retryPolicy); return(true); } return(false); }