Esempio n. 1
0
        TimeSpan ComputeNextDelay(int attempt, DateTime firstAttempt, Exception failure)
        {
            TimeSpan nextDelay = TimeSpan.Zero;

            try
            {
                if (retryOptions.Handle(failure))
                {
                    DateTime retryExpiration = (retryOptions.RetryTimeout != TimeSpan.MaxValue)
                        ? firstAttempt.Add(retryOptions.RetryTimeout)
                        : DateTime.MaxValue;
                    if (context.CurrentUtcDateTime < retryExpiration)
                    {
                        double nextDelayInMilliSeconds = retryOptions.FirstRetryInterval.TotalMilliseconds *
                                                         Math.Pow(retryOptions.BackoffCoefficient, attempt);
                        nextDelay = (nextDelayInMilliSeconds < retryOptions.MaxRetryInterval.TotalMilliseconds)
                            ? TimeSpan.FromMilliseconds(nextDelayInMilliSeconds)
                            : retryOptions.MaxRetryInterval;
                    }
                }
            }
            catch (Exception e)
            {
                // Catch any exceptions during ComputeNextDelay so we don't override original error with new error
                TraceHelper.TraceExceptionInstance(TraceEventType.Error, context.OrchestrationInstance, e);
            }

            return(nextDelay);
        }