From e70f88bcb04f2efd155622360aea72667e1f8ba6 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Mon, 22 Jul 2024 15:23:10 +0200 Subject: [PATCH] set readiness to true after successful ws connection Signed-off-by: Matthias Bertschy --- main.go | 4 +--- pkg/notificationhandle.go | 5 ++++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 7f69679..2d65fe4 100644 --- a/main.go +++ b/main.go @@ -20,9 +20,7 @@ func main() { isReadinessReady := false go probes.InitReadinessV1(&isReadinessReady) - gateway := gateway.NewGateway() - isReadinessReady = true - gateway.SetupAndServe() + gateway.NewGateway(&isReadinessReady).SetupAndServe() } // DisplayBuildTag outputs the bulid tag of the current release diff --git a/pkg/notificationhandle.go b/pkg/notificationhandle.go index fdf4fcd..0ec31d6 100644 --- a/pkg/notificationhandle.go +++ b/pkg/notificationhandle.go @@ -38,10 +38,11 @@ type Gateway struct { incomingConnections Connections outgoingConnectionsMutex *sync.Mutex rootGatewayURL string + isReadinessReady *bool } // NewGateway creates a new Gateway -func NewGateway() *Gateway { +func NewGateway(isReadinessReady *bool) *Gateway { rootGatewayUrl := getRootGwUrl() @@ -51,6 +52,7 @@ func NewGateway() *Gateway { incomingConnections: *NewConnectionsObj(), outgoingConnectionsMutex: &sync.Mutex{}, rootGatewayURL: rootGatewayUrl, + isReadinessReady: isReadinessReady, } } @@ -78,6 +80,7 @@ func (nh *Gateway) WebsocketNotificationHandler(w http.ResponseWriter, r *http.R // append new route newConn, id := nh.incomingConnections.Append(notificationAtt, conn) logger.L().Info("accepting websocket connection", helpers.String("url query", r.URL.RawQuery), helpers.Int("id", id), helpers.Int("number of incoming websockets", nh.incomingConnections.Len())) + *nh.isReadinessReady = true // ----------------------------------------------------- 3 // register route in master if master configured