proxy: add random reload offset for HA
This commit is contained in:
parent
903cdeaa7f
commit
f9cede7b31
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
Reference in a new issue