-
Notifications
You must be signed in to change notification settings - Fork 163
/
retry.go
29 lines (22 loc) · 905 Bytes
/
retry.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (C) 2017 ScyllaDB
package retry
import (
"context"
"github.com/cenkalti/backoff"
)
// An Operation is executing by WithNotify().
// The operation will be retried using a backoff policy if it returns an error.
type Operation = backoff.Operation
// Notify is a notify-on-error function. It receives an operation error and
// backoff delay if the operation failed (with an error).
type Notify = backoff.Notify
// WithNotify calls notify function with the error and wait duration
// for each failed attempt before sleep.
func WithNotify(ctx context.Context, op Operation, b Backoff, n Notify) error {
return backoff.RetryNotify(op, backoff.WithContext(b, ctx), n)
}
// Permanent wraps the given err in a *backoff.PermanentError.
// This error interrupts further retries and causes retrying mechanism.
func Permanent(err error) *backoff.PermanentError {
return backoff.Permanent(err)
}