CircuitBreakerPolicy
class CircuitBreakerPolicy
using System;
using System.Collections.Generic;
using System.Linq;
namespace Polly.CircuitBreaker
{
internal class CircuitBreakerPolicy
{
internal static void Implementation(Action action, IEnumerable<ExceptionPredicate> shouldRetryPredicates, ICircuitBreakerState breakerState)
{
if (breakerState.IsBroken)
throw new BrokenCircuitException("The circuit is now open and is not allowing calls.", breakerState.LastException);
try {
action();
breakerState.Reset();
} catch (Exception ex2) {
Exception ex = ex2;
if (!shouldRetryPredicates.Any((ExceptionPredicate predicate) => predicate(ex)))
throw;
breakerState.TryBreak(ex);
throw;
}
}
}
}