go-ethereum/metrics/healthcheck.go

36 lines
931 B
Go
Raw Normal View History

2015-06-22 04:00:55 -05:00
package metrics
// NewHealthcheck constructs a new Healthcheck which will use the given
// function to update its status.
func NewHealthcheck(f func(*Healthcheck)) *Healthcheck {
return &Healthcheck{nil, f}
2015-06-22 04:00:55 -05:00
}
// Healthcheck is the standard implementation of a Healthcheck and
2015-06-22 04:00:55 -05:00
// stores the status and a function to call to update the status.
type Healthcheck struct {
2015-06-22 04:00:55 -05:00
err error
f func(*Healthcheck)
2015-06-22 04:00:55 -05:00
}
// Check runs the healthcheck function to update the healthcheck's status.
func (h *Healthcheck) Check() {
2015-06-22 04:00:55 -05:00
h.f(h)
}
// Error returns the healthcheck's status, which will be nil if it is healthy.
func (h *Healthcheck) Error() error {
2015-06-22 04:00:55 -05:00
return h.err
}
// Healthy marks the healthcheck as healthy.
func (h *Healthcheck) Healthy() {
2015-06-22 04:00:55 -05:00
h.err = nil
}
// Unhealthy marks the healthcheck as unhealthy. The error is stored and
// may be retrieved by the Error method.
func (h *Healthcheck) Unhealthy(err error) {
2015-06-22 04:00:55 -05:00
h.err = err
}