Skip to content

Commit

Permalink
fix heartbeat error
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblakeley committed Nov 1, 2018
1 parent 71dfa60 commit 931b31d
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dashboard_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,13 @@ func (h *HTTPDashboardHandler) Register() error {
}

func (h *HTTPDashboardHandler) StartBeating() error {

req := h.newRequest(h.HeartBeatEndpoint)

client := initialiseClient(5 * time.Second)

for !h.heartBeatStopSentinel {
if err := h.sendHeartBeat(); err != nil {
if err := h.sendHeartBeat(req, client); err != nil {
log.Warning(err)
}
time.Sleep(time.Second * 2)
Expand All @@ -163,18 +168,18 @@ func (h *HTTPDashboardHandler) newRequest(endpoint string) *http.Request {
return req
}

func (h *HTTPDashboardHandler) sendHeartBeat() error {
req := h.newRequest(h.HeartBeatEndpoint)
func (h *HTTPDashboardHandler) sendHeartBeat(req *http.Request, client *http.Client) error {
req.Header.Set("x-tyk-nodeid", NodeID)
req.Header.Set("x-tyk-nonce", ServiceNonce)
c := initialiseClient(5 * time.Second)

resp, err := c.Do(req)
if err != nil || resp.StatusCode != 200 {
resp, err := client.Do(req)
if err != nil {
return errors.New("dashboard is down? Heartbeat is failing")
}

defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return errors.New("dashboard is down? Heartbeat non-200 response")
}
val := NodeResponseOK{}
if err := json.NewDecoder(resp.Body).Decode(&val); err != nil {
return err
Expand Down

0 comments on commit 931b31d

Please sign in to comment.