forked from go-chassis/go-chassis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backoff.go
37 lines (33 loc) · 944 Bytes
/
backoff.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
30
31
32
33
34
35
36
37
package backoff
import (
"github.com/cenkalti/backoff"
"time"
)
//constant for back off
const (
BackoffJittered = "jittered"
BackoffConstant = "constant"
BackoffZero = "zero"
//DefaultBackOffKind is zero
DefaultBackOffKind = BackoffZero
)
//GetBackOff return the the back off policy
func GetBackOff(kind string, min, max int) backoff.BackOff {
switch kind {
case BackoffJittered:
return &backoff.ExponentialBackOff{
InitialInterval: time.Duration(min) * time.Millisecond,
RandomizationFactor: backoff.DefaultRandomizationFactor,
Multiplier: backoff.DefaultMultiplier,
MaxInterval: time.Duration(max) * time.Millisecond,
MaxElapsedTime: 0,
Clock: backoff.SystemClock,
}
case BackoffConstant:
return backoff.NewConstantBackOff(time.Duration(min) * time.Millisecond)
case BackoffZero:
return &backoff.ZeroBackOff{}
default:
return &backoff.ZeroBackOff{}
}
}