public static int GetBackoffDelay()

in Darabonba/Core.cs [270:312]


        public static int GetBackoffDelay(RetryOptions options, RetryPolicyContext ctx)
        {
            if (ctx.RetriesAttempted == null || ctx.RetriesAttempted == 0)
            {
                return 0;
            }

            if (ctx.Exception is DaraException)
            {
                if (options != null)
                {
                    var daraException = (DaraException)ctx.Exception;
                    var retryConditions = options.RetryCondition;
                    if (retryConditions != null)
                    {
                        foreach (var retryCondition in retryConditions)
                        {
                            if (!DictUtils.Contains(retryCondition.Exception, daraException.Message) && !DictUtils.Contains(retryCondition.ErrorCode, daraException.Code))
                            {
                                continue;
                            }
                            long maxDelay = retryCondition.MaxDelayTimeMillis ?? (long)DefaultMaxDelay.TotalMilliseconds;
                            if (daraException is DaraResponseException)
                            {
                                var responseException = (DaraResponseException)daraException;
                                if (responseException.RetryAfter != null)
                                {
                                    return (int)Math.Min(responseException.RetryAfter.Value, maxDelay);
                                }
                            }
                            if (retryCondition.Backoff == null)
                            {
                                return (int)DefaultMinDelay.TotalMilliseconds;
                            }
                            var delayTimeMillis = retryCondition.Backoff.GetDelayTime(ctx);
                            long delayTime = delayTimeMillis != null ? (long)delayTimeMillis : (long)DefaultMinDelay.TotalMilliseconds;
                            return (int)Math.Min(delayTime, maxDelay);
                        }
                    }
                }
            }
            return  (int)DefaultMinDelay.TotalMilliseconds;
        }