Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/health-endpoints' into feat…
Browse files Browse the repository at this point in the history
…/health-endpoints
  • Loading branch information
Cory Schwartz committed May 23, 2022
2 parents 45d15cb + b485203 commit 0a7fbd0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions node/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import (
var healthlog = logging.Logger("healthcheck")

type HealthHandler struct {
healthy bool
healthy int32
}

func (h *HealthHandler) SetHealthy(healthy bool) {
h.healthy = healthy
h := int32(0)
if healthy {
h = 1
}
atomic.StoreInt32(&h.healthy, h)
}

func (h *HealthHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !h.healthy {
if atomic.LoadInt32(&h.healthy) != 1 {
w.WriteHeader(http.StatusServiceUnavailable)
return
}
Expand Down

0 comments on commit 0a7fbd0

Please sign in to comment.