Пример #1
0
        private bool ShouldStop(RestartStatistics rs)
        {
            if (_maxNrOfRetries == 0)
            {
                return(true);
            }
            rs.Fail();

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

            return(false);
        }
Пример #2
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);
            });
        }