Skip to content

Commit 3251145

Browse files
committed
move to config fix_node timeout
config filled with default values
1 parent bd7e282 commit 3251145

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

config/config.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package config
33
import (
44
"encoding/json"
55
"errors"
6-
"os"
7-
86
log "github.com/sirupsen/logrus"
7+
"os"
98

109
"github.com/qa-dev/jsonwire-grid/pool/metrics"
1110
)
@@ -20,12 +19,14 @@ type Config struct {
2019

2120
// Grid general settings
2221
type Grid struct {
23-
ClientType string `json:"client_type"`
24-
Port int `json:"port"`
25-
StrategyList []Strategy `json:"strategy_list"`
26-
BusyNodeDuration string `json:"busy_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
22+
ClientType string `json:"client_type"`
23+
Port int `json:"port"`
24+
StrategyList []Strategy `json:"strategy_list"`
25+
// duration string format ex. 12m, see time.ParseDuration()
26+
BusyNodeDuration string `json:"busy_node_duration"`
2727
// todo: выпилить и сделать равным дедлайну http запроса
28-
ReservedDuration string `json:"reserved_node_duration"` // duration string format ex. 12m, see time.ParseDuration()
28+
ReservedDuration string `json:"reserved_node_duration"`
29+
FixNodeTimeout string `json:"fix_node_timeout"`
2930
}
3031

3132
// Strategy - Describes the algorithm of node selection.
@@ -63,9 +64,19 @@ type Statsd struct {
6364
CapabilitiesList []metrics.CapabilitiesSelector `json:"selectors"`
6465
}
6566

66-
// New - Constructor of config.
67+
// New - Constructor of config with default values
6768
func New() *Config {
68-
return &Config{}
69+
return &Config{Logger: Logger{Level: "debug"},
70+
DB: DB{Implementation: "local"},
71+
Grid: Grid{
72+
ClientType: "selenium",
73+
Port: 4444,
74+
StrategyList: []Strategy{{Type: "persistent"}},
75+
ReservedDuration: "5m",
76+
BusyNodeDuration: "15m",
77+
FixNodeTimeout: "5m",
78+
},
79+
}
6980
}
7081

7182
// LoadFromFile - config loader from json file.

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ func main() {
4444
if err != nil {
4545
log.Fatal("Invalid value grid.reserved_node_duration in config")
4646
}
47+
fixNodeDuration, err := time.ParseDuration(cfg.Grid.FixNodeTimeout)
48+
if err != nil {
49+
log.Fatal("Invalid value grid.fix_node_timeout in config")
50+
}
4751
storageFactory, err := invokeStorageFactory(*cfg)
4852
if err != nil {
4953
log.Fatalf("Can't invoke storage factory, %s", err)
@@ -80,7 +84,7 @@ func main() {
8084
go func() {
8185
for {
8286
poolInstance.FixNodeStatuses()
83-
time.Sleep(time.Minute * 5) // todo: move to config
87+
time.Sleep(fixNodeDuration)
8488
}
8589
}()
8690

0 commit comments

Comments
 (0)