/// <summary> /// Update host's state /// </summary> /// <param name="tryableHost">A statefull host</param> /// <param name="httpResponseCode">An http response code</param> /// <param name="isTimedOut">Is the request timed out</param> /// <returns></returns> public RetryOutcomeType Decide(StatefulHost tryableHost, int httpResponseCode, bool isTimedOut) { lock (_lock) { if (!isTimedOut && IsSuccess(httpResponseCode)) { tryableHost.Up = true; tryableHost.LastUse = DateTime.UtcNow; return(RetryOutcomeType.Success); } else if (!isTimedOut && IsRetryable(httpResponseCode)) { tryableHost.Up = false; tryableHost.LastUse = DateTime.UtcNow; return(RetryOutcomeType.Retry); } else if (isTimedOut) { tryableHost.Up = true; tryableHost.LastUse = DateTime.UtcNow; tryableHost.RetryCount++; return(RetryOutcomeType.Retry); } return(RetryOutcomeType.Failure); } }
/// <summary> /// Reset the given host /// </summary> /// <param name="host"></param> private void Reset(StatefulHost host) { host.Up = true; host.RetryCount = 0; host.LastUse = DateTime.UtcNow; }