MakeBackoffIntervalFunc returns a new BackoffIntervalFunc.
(onFailure bool, resetDuration time.Duration, intervals ...time.Duration)
| 71 | |
| 72 | // MakeBackoffIntervalFunc returns a new BackoffIntervalFunc. |
| 73 | func MakeBackoffIntervalFunc(onFailure bool, resetDuration time.Duration, intervals ...time.Duration) BackoffIntervalFunc { |
| 74 | return func(ctx context.Context, executionDuration time.Duration, invocation uint, err error) time.Duration { |
| 75 | switch { |
| 76 | case onFailure && err == nil: |
| 77 | return 0 |
| 78 | case executionDuration > resetDuration: |
| 79 | return intervals[0] |
| 80 | case invocation >= uint(len(intervals)): |
| 81 | return intervals[len(intervals)-1] |
| 82 | default: |
| 83 | return intervals[invocation-1] |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Values for DefaultBackoffConfig. |
| 89 | const ( |
no outgoing calls