-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.go
51 lines (46 loc) · 1.44 KB
/
configure.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package hystrix
import (
"github.com/afex/hystrix-go/hystrix"
)
// CommandConfig is used to tune circuit settings at runtime
type CommandConfig struct {
Timeout int
MaxConcurrentRequests int
RequestVolumeThreshold int
SleepWindow int
ErrorPercentThreshold int
}
// Configure applies settings for a set of circuits
func Configure(cmds map[string]CommandConfig) {
for k, v := range cmds {
ConfigureCommand(k, v)
}
}
// ConfigureCommand applies settings for a circuit
func ConfigureCommand(name string, config CommandConfig) {
hystrix.ConfigureCommand(name, hystrix.CommandConfig{
Timeout: config.Timeout,
MaxConcurrentRequests: config.MaxConcurrentRequests,
RequestVolumeThreshold: config.RequestVolumeThreshold,
SleepWindow: config.SleepWindow,
ErrorPercentThreshold: config.ErrorPercentThreshold,
})
}
// ConfigureDefault applies default settings for all circuits
func ConfigureDefault(config CommandConfig) {
if config.Timeout != 0 {
hystrix.DefaultTimeout = config.Timeout
}
if config.MaxConcurrentRequests != 0 {
hystrix.DefaultMaxConcurrent = config.MaxConcurrentRequests
}
if config.RequestVolumeThreshold != 0 {
hystrix.DefaultVolumeThreshold = config.RequestVolumeThreshold
}
if config.SleepWindow != 0 {
hystrix.DefaultSleepWindow = config.SleepWindow
}
if config.ErrorPercentThreshold != 0 {
hystrix.DefaultErrorPercentThreshold = config.ErrorPercentThreshold
}
}