示例#1
0
 private AsyncRetryPolicy<IConnection> CreateConnectionRetryPolicy(IRecoveryPolicy recoveryPolicy)
 {
     return Policy<IConnection>
            .Handle<Exception>()
            .WaitAndRetryAsync(recoveryPolicy.RetryCount, (retryAttempt, context) =>
            {
                context.SetRetryCount(retryAttempt);
                return recoveryPolicy.GetDelay(retryAttempt);
            }, (result, _, context) =>
            {
                var retryCount = context.GetRetryCount();
                var endpoint = GetCurrentEndpoint(context);
                if (result.Exception != null)
                {
                    Log.FailedToEstablishConnection(_logger, endpoint, retryCount, result.Exception);
                }
                else
                {
                    Log.ConnectionEstablished(_logger, endpoint, retryCount);
                }
            });
 }
 public static double[] GetDelays(IRecoveryPolicy recoveryPolicy)
 {
     return(Enumerable.Range(1, 5).Select(x => recoveryPolicy.GetDelay(x).TotalMilliseconds).ToArray());
 }