-
Notifications
You must be signed in to change notification settings - Fork 21
/
config.go
107 lines (98 loc) · 2.87 KB
/
config.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package dalga
import (
"fmt"
"net/url"
"time"
)
// DefaultConfig contains sensible defaults for Dalga instance.
// For a simple deployment, you only need to override MySQL options.
var DefaultConfig = Config{
Jobs: jobsConfig{
RetryInterval: time.Minute,
RetryMultiplier: 1,
RetryMaxInterval: time.Minute,
ScanFrequency: time.Second,
MaxRunning: 100,
},
MySQL: mysqlConfig{
Host: "127.0.0.1",
Port: 3306,
DB: "test",
Table: "dalga",
User: "root",
Password: "",
MaxOpenConns: 50,
SkipLocked: true,
TransactionIsolationParamName: "transaction_isolation",
DialTimeout: 30 * time.Second,
ReadTimeout: 30 * time.Second,
WriteTimeout: 30 * time.Second,
},
Listen: listenConfig{
Host: "127.0.0.1",
Port: 34006,
ShutdownTimeout: 10 * time.Second,
IdleTimeout: 60 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
},
Endpoint: endpointConfig{
BaseURL: "http://127.0.0.1:5000/",
Timeout: 10 * time.Second,
},
}
// Config values for Dalga instance.
type Config struct {
Jobs jobsConfig
MySQL mysqlConfig
Listen listenConfig
Endpoint endpointConfig
}
type jobsConfig struct {
RandomizationFactor float64
RetryInterval time.Duration
RetryMultiplier float64
RetryMaxInterval time.Duration
RetryStopAfter time.Duration
FixedIntervals bool
ScanFrequency time.Duration
MaxRunning int
}
type mysqlConfig struct {
Host string
Port int
DB string
Table string
User string
Password string
MaxOpenConns int
SkipLocked bool
TransactionIsolationParamName string
DialTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
func (c mysqlConfig) DSN() string {
v := url.Values{}
v.Set("parseTime", "true")
v.Set(c.TransactionIsolationParamName, "'READ-COMMITTED'")
v.Set("timeout", c.DialTimeout.String())
v.Set("readTimeout", c.ReadTimeout.String())
v.Set("writeTimeout", c.WriteTimeout.String())
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?", c.User, c.Password, c.Host, c.Port, c.DB) + v.Encode()
}
type listenConfig struct {
Host string
Port int
ShutdownTimeout time.Duration
IdleTimeout time.Duration
ReadTimeout time.Duration
WriteTimeout time.Duration
}
func (c listenConfig) Addr() string {
return fmt.Sprintf("%s:%d", c.Host, c.Port)
}
type endpointConfig struct {
BaseURL string
Timeout time.Duration
}