From c439b3194026685db85aa280ff521411c90864d3 Mon Sep 17 00:00:00 2001 From: Link Dupont Date: Tue, 19 Sep 2023 11:20:29 -0400 Subject: [PATCH] fix: default mqtt-auto-reconnect to true Signed-off-by: Link Dupont --- cmd/yggd/main.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/yggd/main.go b/cmd/yggd/main.go index 7f81cb48..7c03b0b3 100644 --- a/cmd/yggd/main.go +++ b/cmd/yggd/main.go @@ -113,7 +113,7 @@ func main() { altsrc.NewBoolFlag(&cli.BoolFlag{ Name: "mqtt-auto-reconnect", Usage: "Enable automatic reconnection when the client disconnects", - Value: false, + Value: true, Hidden: true, }), altsrc.NewDurationFlag(&cli.DurationFlag{ @@ -288,17 +288,16 @@ func main() { }) mqttClientOpts.SetReconnectingHandler(func(_ mqtt.Client, co *mqtt.ClientOptions) { - log.Debugf("reconnecting to broker: %v", co.Servers) - reconnectDelay := c.Duration("mqtt-reconnect-delay") if reconnectDelay > 0 { log.Infof( - "delaying for %v before reconnection", + "delaying for %v before reconnecting...", reconnectDelay, ) time.Sleep(reconnectDelay) } + log.Debugf("reconnecting to broker: %v", co.Servers) }) data, err := json.Marshal(&yggdrasil.ConnectionStatus{ @@ -318,7 +317,12 @@ func main() { if err != nil { return cli.Exit(fmt.Errorf("cannot marshal message to JSON: %w", err), 1) } - mqttClientOpts.SetBinaryWill(fmt.Sprintf("%v/%v/control/out", yggdrasil.TopicPrefix, ClientID), data, 1, false) + mqttClientOpts.SetBinaryWill( + fmt.Sprintf("%v/%v/control/out", yggdrasil.TopicPrefix, ClientID), + data, + 1, + false, + ) mqttClient := mqtt.NewClient(mqttClientOpts) if token := mqttClient.Connect(); token.Wait() && token.Error() != nil {