summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-09-24 13:04:16 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-09-24 13:04:16 (GMT)
commit1e775fc17c784d46ef1286db351ecfda5d212201 (patch)
treedca73f73c645cc09ac7e0bf797420867ddf6a151
parent301ad925c1e202f4264ae5d45e21e4f0a837458c (diff)
make settling times configurable
-rw-r--r--sample-config.toml14
-rw-r--r--src/rhctl/conf.go16
-rw-r--r--src/rhctl/switch_control.go35
3 files changed, 57 insertions, 8 deletions
diff --git a/sample-config.toml b/sample-config.toml
index 5597ff2..1d50503 100644
--- a/sample-config.toml
+++ b/sample-config.toml
@@ -8,6 +8,7 @@ inputs = [ { number = 1, server = "master", channel = "main" },
{ number = 3, server = "standby", channel = "main" },
{ number = 4, server = "standby", channel = "music" } ]
+
[servers]
[servers.master]
@@ -18,6 +19,19 @@ inputs = [ { number = 1, server = "master", channel = "main" },
# dev = "/dev/ttyUSB2"
# baud = 38400
+
+# [timing]
+
+# [timing.settling]
+# awakening = "30s"
+# select_server = "10s"
+# update_states = "3s"
+
+# [timing.stale_states]
+# check_interval = "1m"
+# max_age = "2h"
+
+
[clients]
[clients.web]
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go
index 8df11f0..3e35abb 100644
--- a/src/rhctl/conf.go
+++ b/src/rhctl/conf.go
@@ -73,6 +73,19 @@ type Config struct {
HeartbeatThreshold uint `toml:"heartbeat_threshold"`
}
+ Timing struct {
+ Settling struct {
+ Awakening Duration `toml:"awakening"`
+ SelectServer Duration `toml:"select_server"`
+ UpdateStates Duration `toml:"update_states"`
+ }
+
+ StaleStates struct {
+ CheckInterval Duration `toml:"check_interval"`
+ MaxAge Duration `toml:"max_age"`
+ }
+ }
+
Clients struct {
Web struct {
Address string `toml:"addr"`
@@ -90,6 +103,9 @@ type Duration struct {
func (d *Duration) UnmarshalTOML(data []byte) (err error) {
ds := strings.Trim(string(data), "\"")
d.Duration, err = time.ParseDuration(ds)
+ if err == nil && d.Duration < 0 {
+ err = errors.New("negative durations are not allowed")
+ }
return
}
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 1cfd4f8..71f2d69 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -93,11 +93,11 @@ type SwitchControl struct {
settling *time.Timer
Updates *pubsub.PubSub
Commands chan *Command
- AwakeningSettlingTime time.Duration // 30 * time.Second
- SelectServerSettlingTime time.Duration // 10 * time.Second
- UpdateStatesSettlingTime time.Duration // 3 * time.Second
- StaleStateCheckInterval time.Duration // 1 * time.Minute
- StatesMaxAge time.Duration // 2 * time.Hour
+ AwakeningSettlingTime time.Duration
+ SelectServerSettlingTime time.Duration
+ UpdateStatesSettlingTime time.Duration
+ StaleStatesCheckInterval time.Duration
+ StatesMaxAge time.Duration
}
func (ctrl *SwitchControl) handleCommand(cmd *Command) {
@@ -331,7 +331,7 @@ func (ctrl *SwitchControl) Run() {
// send out commands to switch and/or server to get missing infos
ctrl.checkMissingOrStaleStates(0)
- staleTicker := time.NewTicker(ctrl.StaleStateCheckInterval)
+ staleTicker := time.NewTicker(ctrl.StaleStatesCheckInterval)
ctrl.reconcile("")
for {
@@ -380,11 +380,30 @@ func SwitchControlInit(conf *Config, sw *AudioSwitch, servers []*PlayoutServer)
ctrl.Updates = pubsub.NewNonBlocking(32)
ctrl.Commands = make(chan *Command, 8)
- // TODO: get this from conf
ctrl.AwakeningSettlingTime = 30 * time.Second
+ if conf.Timing.Settling.Awakening.Duration > time.Duration(0) {
+ ctrl.AwakeningSettlingTime = conf.Timing.Settling.Awakening.Duration
+ }
+
ctrl.SelectServerSettlingTime = 10 * time.Second
+ if conf.Timing.Settling.SelectServer.Duration > time.Duration(0) {
+ ctrl.SelectServerSettlingTime = conf.Timing.Settling.SelectServer.Duration
+ }
+
ctrl.UpdateStatesSettlingTime = 3 * time.Second
- ctrl.StaleStateCheckInterval = 1 * time.Minute
+ if conf.Timing.Settling.UpdateStates.Duration > time.Duration(0) {
+ ctrl.UpdateStatesSettlingTime = conf.Timing.Settling.UpdateStates.Duration
+ }
+
+ ctrl.StaleStatesCheckInterval = 1 * time.Minute
+ if conf.Timing.StaleStates.CheckInterval.Duration > time.Duration(0) {
+ ctrl.StaleStatesCheckInterval = conf.Timing.StaleStates.CheckInterval.Duration
+ }
+
ctrl.StatesMaxAge = 2 * time.Hour
+ if conf.Timing.StaleStates.MaxAge.Duration > time.Duration(0) {
+ ctrl.StatesMaxAge = conf.Timing.StaleStates.MaxAge.Duration
+ }
+
return
}