2023-03-23 04:58:10 +00:00
|
|
|
package backoff
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-04-12 05:49:29 +00:00
|
|
|
"time"
|
2023-03-23 04:58:10 +00:00
|
|
|
|
|
|
|
"github.com/cenkalti/backoff/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
var MaxRetries uint64 = 101
|
|
|
|
|
2023-04-11 10:21:40 +00:00
|
|
|
// RetryGeneral retries operation with max retry times 101 and with the exponential backoff
|
2023-04-12 05:49:29 +00:00
|
|
|
func RetryGeneral(parent context.Context, op backoff.Operation) (err error) {
|
|
|
|
ctx, cancel := context.WithTimeout(parent, 15*time.Minute)
|
|
|
|
defer cancel()
|
|
|
|
|
2023-03-23 04:58:10 +00:00
|
|
|
err = backoff.Retry(op, backoff.WithContext(
|
|
|
|
backoff.WithMaxRetries(
|
|
|
|
backoff.NewExponentialBackOff(),
|
|
|
|
MaxRetries),
|
|
|
|
ctx))
|
|
|
|
return err
|
|
|
|
}
|