private void SetCurrentState(CircuitBreakerStateDescriptor newState)
 {
     if (stateDescriptor != newState)
     {
         stateDescriptor = newState;
         logger.Event("CircuitBreakerTransition", ("circuitBreakerType", key),
                      ("circuitBreakerState", newState));
     }
 }
Пример #2
0
            public Task <CircuitBreakerStateDescriptor> GetLastStateAsync()
            {
                if (stateDescriptor == null)
                {
                    stateDescriptor =
                        new CircuitBreakerStateDescriptor(CircuitBreakerState.Closed, Clock.Current.Now());
                }

                return(Task.FromResult(stateDescriptor));
            }
Пример #3
0
            public async Task SignalSuccessAsync()
            {
                await Task.Yield();

                if (stateDescriptor?.State != CircuitBreakerState.Closed)
                {
                    var newState = new CircuitBreakerStateDescriptor(stateDescriptor?.State == CircuitBreakerState.Open ? CircuitBreakerState.HalfOpen : CircuitBreakerState.Closed, Clock.Current.Now());
                    SetCurrentState(newState);
                }
                NotifyState();
            }
Пример #4
0
            public async Task SignalFailureAsync(TimeSpan expiry)
            {
                await Task.Yield();

                var open = new CircuitBreakerStateDescriptor(CircuitBreakerState.Open, Clock.Current.Now(), expiry);

                Clock.Current.Schedule(_ =>
                {
                    if (ReferenceEquals(stateDescriptor, open))
                    {
                        var halfOpen = new CircuitBreakerStateDescriptor(CircuitBreakerState.HalfOpen, Clock.Current.Now());
                        SetCurrentState(halfOpen);
                        NotifyState();
                    }
                }, expiry);
                SetCurrentState(open);
                NotifyState();
            }
Пример #5
0
 public CircuitBreakerStoragePartition(string key)
 {
     this.key        = key;
     subscribers     = new ConcurrentSet <CircuitBreakerBrokerSubscriber>();
     stateDescriptor = new CircuitBreakerStateDescriptor(CircuitBreakerState.Closed, Clock.Current.Now(), TimeSpan.FromMinutes(2));
 }
Пример #6
0
 private void StateChanged(CircuitBreakerStateDescriptor descriptor) => stateDescriptor = descriptor;