func WithRetries()

in pkg/download/retry.go [32:55]


func WithRetries(ctx *log.Context, d Downloader, sf SleepFunc) (io.ReadCloser, error) {
	var lastErr error
	for n := 0; n < expRetryN; n++ {
		ctx := ctx.With("retry", n)
		out, err := Download(d)
		if err == nil {
			return out, nil
		}
		lastErr = err
		ctx.Log("error", err)

		if out != nil { // we are not going to read this response body
			out.Close()
		}

		if n != expRetryN-1 {
			// have more retries to go, sleep before retrying
			slp := expRetryK * time.Duration(int(math.Pow(float64(expRetryM), float64(n))))
			ctx.Log("sleep", slp)
			sf(slp)
		}
	}
	return nil, lastErr
}