示例#1
0
 private void SetFailureCount(RestartStatistics rs)
 {
     // if we are within the backoff window, exit early
     if (rs.IsWithinDuration(_backoffWindow))
     {
         rs.Fail();
         return;
     }
     //we are past the backoff limit, reset the failure counter
     rs.Reset();
 }
示例#2
0
 private bool RequestRestartPermission(RestartStatistics rs)
 {
     if (_maxNrOfRetries == 0)
     {
         return(false);
     }
     rs.Fail();
     if (_withinTimeSpan == null || rs.IsWithinDuration(_withinTimeSpan.Value))
     {
         return(rs.FailureCount <= _maxNrOfRetries);
     }
     rs.Reset();
     return(true);
 }
示例#3
0
        private bool ShouldStop(RestartStatistics rs)
        {
            if (_maxNrOfRetries == 0)
            {
                return(true);
            }
            rs.Fail();

            if (rs.NumberOfFailures(_withinTimeSpan) > _maxNrOfRetries)
            {
                rs.Reset();
                return(true);
            }

            return(false);
        }
示例#4
0
        public void HandleFailure(ISupervisor supervisor, PID child, RestartStatistics rs, Exception reason, object message)
        {
            if (rs.NumberOfFailures(_backoffWindow) == 0)
            {
                rs.Reset();
            }

            rs.Fail();

            var backoff  = rs.FailureCount * ToNanoseconds(_initialBackoff);
            var noise    = _random.Next(500);
            var duration = TimeSpan.FromMilliseconds(ToMilliseconds(backoff + noise));

            Task.Delay(duration).ContinueWith(t =>
            {
                supervisor.RestartChildren(reason, child);
            });
        }