コード例 #1
0
        private async Task <IResponse> HandleRetryInternally(
            IRequest request,
            IResponse response,
            IRetryHandler.RetryFunc retry,
            int triesLeft)
        {
            var secondsToWait = ParseTooManyRetries(response);

            if (secondsToWait != null && (!TooManyRequestsConsumesARetry || triesLeft > 0))
            {
                await _sleep(secondsToWait.Value).ConfigureAwait(false);

                response = await retry(request).ConfigureAwait(false);

                var newTriesLeft = TooManyRequestsConsumesARetry ? triesLeft - 1 : triesLeft;
                return(await HandleRetryInternally(request, response, retry, newTriesLeft).ConfigureAwait(false));
            }

            while (RetryErrorCodes.Contains(response.StatusCode) && triesLeft > 0)
            {
                await _sleep(RetryAfter).ConfigureAwait(false);

                response = await retry(request).ConfigureAwait(false);

                return(await HandleRetryInternally(request, response, retry, triesLeft - 1).ConfigureAwait(false));
            }

            return(response);
        }
コード例 #2
0
        public Task <IResponse> HandleRetry(IRequest request, IResponse response, IRetryHandler.RetryFunc retry)
        {
            Ensure.ArgumentNotNull(response, nameof(response));
            Ensure.ArgumentNotNull(retry, nameof(retry));

            return(HandleRetryInternally(request, response, retry, RetryTimes));
        }