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(); }
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); }
private bool ShouldStop(RestartStatistics rs) { if (_maxNrOfRetries == 0) { return(true); } rs.Fail(); if (rs.NumberOfFailures(_withinTimeSpan) > _maxNrOfRetries) { rs.Reset(); return(true); } return(false); }
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); }); }