func Retry(retryDuration time.Duration, retries int, callback func() error, friendlyName string) (err error) {
	attempts := 0

	for {
		t0 := time.Now()
		err = callback()
		if err == nil {
			return nil
		}
		switch err.(type) {
		case RetryableError:
			// proceed with retry
		default:
			// No retry requested, return the error
			return err
		}

		// how much did the callback run?
		execDuration := time.Now().Sub(t0)
		if execDuration < retryDuration {
			// the callback failed too soon, retry but increment the counter
			attempts++
		} else {
			// the callback failed after the retryDuration, reset the counter
			attempts = 0
		}

		if attempts == retries {
			// give up
			return fmt.Errorf("bail out from %s, max retries reached, last error: %v", friendlyName, err)
		}

		log.Warnf("retrying %s, got the error: %v", friendlyName, err)
	}
}
// Retry retries a callback up to `retries`-times in a `retryDuration` period of time, and bails out
// if the limit is reached.
Retry retries a callback up to `retries`-times in a `retryDuration` period of time, and bails out
if the limit is reached.
// Retry retries a callback up to ` retries ` - times in a ` retryDuration ` period of time and bails out // if the limit is reached .
func Retry(retryDuration time.Duration, retries int, callback func() error, friendlyName string) (err error) {
	attempts := 0
	for {
		t0 := time.Now()
		err = callback()
		if err == nil {
			return nil
		}
		switch err.(type) {
		case RetryableError:
		default:
			return err
		}
		execDuration := time.Now().Sub(t0)
		if execDuration < retryDuration {
			attempts++
		} else {
			attempts = 0
		}
		if attempts == retries {
			return fmt.Errorf("bail out from %s, max retries reached, last error: %v", friendlyName, err)
		}
		log.Warnf("retrying %s, got the error: %v", friendlyName, err)
	}
}
func Retry ( retryDuration time . Duration , retries int , callback func ( ) error , friendlyName string ) ( err error ) { attempts := 0 for { t0 := time . Now ( ) err = callback ( ) if err == nil { return nil } switch err . ( type ) { case RetryableError : default : return err } execDuration := time . Now ( ) . Sub ( t0 ) if execDuration < retryDuration { attempts ++ } else { attempts = 0 } if attempts == retries { return fmt . Errorf ( " " , friendlyName , err ) } log . Warnf ( " " , friendlyName , err ) } }
Retry retries a callback up to `retries`-times in a `retryDuration` period of time, and bails out
if the limit is reached.
Retry retries a callback up to ` retries ` - times in a ` retryDuration ` period of time and bails out if the limit is reached .
// proceed with retry // No retry requested, return the error // how much did the callback run? // the callback failed too soon, retry but increment the counter // the callback failed after the retryDuration, reset the counter // give up