From 80c2ac8ed35ad24cfe8d6a2477a30bb7588d6316 Mon Sep 17 00:00:00 2001 From: Calvin Zachman Date: Fri, 26 Jan 2024 12:54:41 -0600 Subject: [PATCH] lnd/healthcheck: add health checks dynamically Allow health checks to be added to our monitor after the initial startup. --- healthcheck/healthcheck.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/healthcheck/healthcheck.go b/healthcheck/healthcheck.go index e72d65620..137457d69 100644 --- a/healthcheck/healthcheck.go +++ b/healthcheck/healthcheck.go @@ -96,6 +96,19 @@ func (m *Monitor) Stop() error { return nil } +// AddCheck adds a new healthcheck to our monitor. +func (m *Monitor) AddCheck(check *Observation) error { + + m.wg.Add(1) + go func(check *Observation) { + defer m.wg.Done() + + check.monitor(m.cfg.Shutdown, m.quit) + }(check) + + return nil +} + // CreateCheck is a helper function that takes a function that produces an error // and wraps it in a function that returns its result on an error channel. // We do not wait group the goroutine running our checkFunc because we expect