From fe5fd7fce91de768af761514ba7315e687150200 Mon Sep 17 00:00:00 2001 From: Abhishek Kondur Date: Wed, 5 Oct 2022 21:21:34 +0530 Subject: [PATCH] do checkin after mq is connected, publish metrics only when node is connected --- netclient/functions/daemon.go | 11 ++++++++++- netclient/functions/mqpublish.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/netclient/functions/daemon.go b/netclient/functions/daemon.go index afcf70fd..ae626564 100644 --- a/netclient/functions/daemon.go +++ b/netclient/functions/daemon.go @@ -68,12 +68,14 @@ func Daemon() error { cancel() logger.Log(0, "shutting down netclient daemon") wg.Wait() + mqclient.Disconnect(250) logger.Log(0, "shutdown complete") return nil case <-reset: logger.Log(0, "received reset") cancel() wg.Wait() + mqclient.Disconnect(250) logger.Log(0, "restarting daemon") cancel = startGoRoutines(&wg) } @@ -109,7 +111,14 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc { } } wg.Add(1) - go Checkin(ctx, wg) + for { + if mqclient != nil && mqclient.IsConnected() { + go Checkin(ctx, wg) + break + } + time.Sleep(time.Second) + } + return cancel } diff --git a/netclient/functions/mqpublish.go b/netclient/functions/mqpublish.go index e2ef7bc9..fe33a3fd 100644 --- a/netclient/functions/mqpublish.go +++ b/netclient/functions/mqpublish.go @@ -107,7 +107,7 @@ func checkin() { config.Write(&nodeCfg, nodeCfg.Network) } Hello(&nodeCfg) - if nodeCfg.Server.Is_EE { + if nodeCfg.Server.Is_EE && nodeCfg.Node.Connected == "yes" { logger.Log(0, "collecting metrics for node", nodeCfg.Node.Name) publishMetrics(&nodeCfg) }