summaryrefslogtreecommitdiff
path: root/cmd/dolmetschctl/dolmetschctl.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/dolmetschctl/dolmetschctl.go')
-rw-r--r--cmd/dolmetschctl/dolmetschctl.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/cmd/dolmetschctl/dolmetschctl.go b/cmd/dolmetschctl/dolmetschctl.go
index 86fde95..62b176d 100644
--- a/cmd/dolmetschctl/dolmetschctl.go
+++ b/cmd/dolmetschctl/dolmetschctl.go
@@ -70,7 +70,6 @@ func wsReader(ws *websocket.Conn, ch chan<- types.WebSocketResponseFull) {
io.Copy(ioutil.Discard, r) // consume all the data
}
}
- return
}
func handleControllerEvent(ctrl *controller.Controller, ws *websocket.Conn, ev controller.Event) error {
@@ -120,7 +119,7 @@ func handleWebSocketMessage(ctrl *controller.Controller, ws *websocket.Conn, msg
return nil
}
-func run(ctrl *controller.Controller, ws *websocket.Conn) error {
+func run(ctrl *controller.Controller, ws *websocket.Conn) (error, bool) {
ctrlCh := make(chan controller.Event, 100)
unsub := ctrl.Subscribe(ctrlCh)
defer close(unsub)
@@ -129,7 +128,7 @@ func run(ctrl *controller.Controller, ws *websocket.Conn) error {
go wsReader(ws, wsCh)
if err := ws.WriteJSON(types.WebSocketRequest{Command: "subscribe"}); err != nil {
- return err
+ return err, true
}
log.Printf("subscribed to state changes!")
@@ -137,21 +136,20 @@ func run(ctrl *controller.Controller, ws *websocket.Conn) error {
select {
case ev, ok := <-ctrlCh:
if !ok {
- return fmt.Errorf("controller channel was closed.")
+ return fmt.Errorf("controller channel was closed."), false
}
if err := handleControllerEvent(ctrl, ws, ev); err != nil {
- return err
+ return err, true
}
case msg, ok := <-wsCh:
if !ok {
- return fmt.Errorf("websocket channel was closed.")
+ return fmt.Errorf("websocket channel was closed."), true
}
if err := handleWebSocketMessage(ctrl, ws, msg); err != nil {
- return err
+ return err, true
}
}
}
- return nil
}
func main() {
@@ -176,8 +174,13 @@ func main() {
log.Printf("Error connecting to daemon: %v", err)
} else {
log.Printf("successfully conncted!")
- err := run(c, ws)
- log.Printf("run() returned: %v", err)
+ err, restart := run(c, ws)
+ if restart {
+ log.Printf("run() returned temporary error: %v", err)
+ } else {
+ log.Printf("run() returned fatal error: %v", err)
+ break
+ }
}
log.Printf("will retry in one second...")
time.Sleep(time.Second)