diff --git a/proxy/pkg/server/api.go b/proxy/pkg/server/api.go index d0dd8a0a6..cce8409c5 100644 --- a/proxy/pkg/server/api.go +++ b/proxy/pkg/server/api.go @@ -3,6 +3,7 @@ package server import ( "crypto/sha512" "encoding/hex" + "math/rand" "net/http" "net/url" "os" @@ -38,6 +39,8 @@ type APIController struct { lastBundleHash string logger *log.Entry + reloadOffset time.Duration + wsConn *recws.RecConn } @@ -130,8 +133,11 @@ func NewAPIController(pbURL url.URL, token string) *APIController { commonOpts: getCommonOptions(), server: NewServer(), + reloadOffset: time.Duration(rand.Intn(10)) * time.Second, + lastBundleHash: "", } + ac.logger.Debugf("HA Reload offset: %s", ac.reloadOffset) ac.initWS(pbURL, outpost.Pk) return ac } diff --git a/proxy/pkg/server/api_ws.go b/proxy/pkg/server/api_ws.go index 064c3c34c..0266413df 100644 --- a/proxy/pkg/server/api_ws.go +++ b/proxy/pkg/server/api_ws.go @@ -82,6 +82,7 @@ func (ac *APIController) startWSHandler() { continue } if wsMsg.Instruction == WebsocketInstructionTriggerUpdate { + time.Sleep(ac.reloadOffset) err := ac.UpdateIfRequired() if err != nil { ac.logger.WithField("loop", "ws-handler").WithError(err).Debug("Failed to update")