// Retry calls into the backoff strategy and its wait interval.
979025
func (r *BackoffRetrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
	wait, goahead := r.backoff.Next(retry)
	return wait, goahead, nil
}
76141
func (p *asyncProducer) retryHandler() {
	var msg *ProducerMessage
	buf := queue.New()

	for {
		if buf.Length() == 0 {
			msg = <-p.retries
		} else {
			select {
			case msg = <-p.retries:
			case p.input <- buf.Peek().(*ProducerMessage):
				buf.Remove()
				continue
			}
		}

		if msg == nil {
			return
		}

		buf.Add(msg)
	}
}
798115
func (m *RetryPolicy_RetryBackOff) Validate() error {
	if m == nil {
		return nil
	}

	if m.GetBaseInterval() == nil {
		return RetryPolicy_RetryBackOffValidationError{
			field:  "BaseInterval",
			reason: "value is required",
		}
	}

	if d := m.GetBaseInterval(); d != nil {
		dur := *d

		gt := time.Duration(0*time.Second + 0*time.Nanosecond)

		if dur <= gt {
			return RetryPolicy_RetryBackOffValidationError{
				field:  "BaseInterval",
				reason: "value must be greater than 0s",
			}
		}

	}

	if d := m.GetMaxInterval(); d != nil {
		dur := *d

		gt := time.Duration(0*time.Second + 0*time.Nanosecond)

		if dur <= gt {
			return RetryPolicy_RetryBackOffValidationError{
				field:  "MaxInterval",
				reason: "value must be greater than 0s",
			}
		}

	}

	return nil
}
337362
func (pool *Pool) RetryAfter(after time.Duration) *Pool {
	pool.conf.RetryAfter = after
	return &Pool{redis: pool.redis, conf: pool.conf}
}
500586
func Retries(i int) Option {
	return func(o *Options) {
		o.CallOptions.Retries = i
	}
}
493020
func (cd *ConnectionDetails) RetrySleep() time.Duration {
	d, err := time.ParseDuration(defaults.String(cd.Options["retry_sleep"], "1ms"))
	if err != nil {
		return 1 * time.Millisecond
	}
	return d
}
41756
func Retry(fn RetryFunc) Option {
	return func(o *Options) {
		o.CallOptions.Retry = fn
	}
}
812351
func Retry(n uint, interval time.Duration, fn func() error) (err error) {
	return WithContext(context.Background(), n, interval, fn)
}
1144386
func BackOff(attempts uint) int {
	upper := int(math.Min(float64(retryBackOffCap), float64(retryBackOffBase)*math.Pow(2.0, float64(attempts))))
	sleep := time.Duration(rand.Intn(upper)) * time.Millisecond
	time.Sleep(sleep)
	return int(sleep)
}
244560
func (p *Producer) backoff(failed int) {
	backoff := p.Backoff.Duration()

	p.Logger.WithFields(log.Fields{
		"failures": failed,
		"backoff":  backoff,
	}).Warn("put failures")

	time.Sleep(backoff)
}
216118
func retry(ctx context.Context, f func() bool, delay time.Duration) error {
	if f() {
		return nil
	}

	ticker := time.NewTicker(delay)
	errChan := make(chan error)

	go func() {
		defer close(errChan)

		for {
			select {
			case <-ctx.Done():
				errChan <- ctx.Err()
				return
			case <-ticker.C:
				if f() {
					return
				}
			}
		}
	}()

	return <-errChan
}
603678
func (f *Facade) retryUnlockTenant(ctx datastore.Context, tenantID string, cancel <-chan time.Time, interval time.Duration) error {
	for {
		if err := f.unlockTenant(ctx, tenantID); err == nil {
			return nil
		}
		glog.Warningf("Could not unlock, retrying in %s", interval)
		select {
		case <-time.After(interval):
		case <-cancel:
			return errors.New("operation cancelled")
		}
	}
}
789086
func retry(op Op, times int) Op {
	return func(req rets.Requester, urls rets.CapabilityURLs) error {
		var err error
		for ; times > 0; times-- {
			err = op(req, urls)
			if err == nil {
				return nil
			}
		}
		return err
	}
}
33100
func (b *ExponentialBackoff) backoff(failures uint64) time.Duration {
	if failures <= 0 {
		// proceed normally when there are no failures.
		return 0
	}

	factor := b.config.Factor
	if factor <= 0 {
		factor = DefaultExponentialBackoffConfig.Factor
	}

	backoff := b.config.Base + factor*time.Duration(1<<(failures-1))

	max := b.config.Max
	if max <= 0 {
		max = DefaultExponentialBackoffConfig.Max
	}

	if backoff > max || backoff < 0 {
		backoff = max
	}

	// Choose a uniformly distributed value from [0, backoff).
	return time.Duration(rand.Int63n(int64(backoff)))
}
232165
func (r *retrier) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
	// Fail hard on a specific error
	if err == syscall.ECONNREFUSED {
		err = errors.New("Elasticsearch or network down")
		r.logger.Error(err)
		return 0, false, err
	}

	// Stop after n retries
	if retry >= r.retry {
		r.logger.Debugf("Stop retrying after '%d' retries", retry)
		return 0, false, nil
	}

	// Let the backoff strategy decide how long to wait and whether to stop
	r.logger.Debugln("Retry to connect to Elasticsearch")
	wait, stop := r.backoff.Next(retry)
	return wait, stop, nil
}
713882
func Retry(ctx context.Context, p Policy, e Executer) error {
	b, cancel := p.Start(ctx)
	defer cancel()

	for Continue(b) {
		err := e.Execute(ctx)
		if err == nil {
			return nil
		}

		if IsPermanentError(err) {
			return errors.Wrap(err, `permanent error`)
		}
	}
	return errors.New(`retry attempts failed`)
}
1277306
func (q *Query) RetryPolicy(r RetryPolicy) *Query {
	q.rt = r
	return q
}