From 4382259b6c3c21d7246214bf62f8774e41600a7a Mon Sep 17 00:00:00 2001 From: andig Date: Wed, 23 Feb 2022 13:13:10 +0100 Subject: [PATCH] Make health check honor update interval (#2683) --- core/health.go | 8 ++++++++ core/site.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/health.go b/core/health.go index 40b9381d1..8998660c2 100644 --- a/core/health.go +++ b/core/health.go @@ -19,6 +19,10 @@ func NewHealth(timeout time.Duration) (health *Health) { // Healthy returns health status based on last update timestamp func (health *Health) Healthy() bool { + if health == nil { + return false + } + start := time.Now() for time.Since(start) < time.Second { @@ -35,6 +39,10 @@ func (health *Health) Healthy() bool { // Update updates the health timer on each loadpoint update func (health *Health) Update() { + if health == nil { + return + } + start := time.Now() for time.Since(start) < time.Second { diff --git a/core/site.go b/core/site.go index 0ded86fb8..83c321cb0 100644 --- a/core/site.go +++ b/core/site.go @@ -127,7 +127,6 @@ func NewSiteFromConfig( func NewSite() *Site { lp := &Site{ log: util.NewLogger("site"), - Health: NewHealth(60 * time.Second), Voltage: 230, // V } @@ -476,6 +475,8 @@ func (site *Site) loopLoadpoints(next chan<- Updater) { // Run is the main control loop. It reacts to trigger events by // updating measurements and executing control logic. func (site *Site) Run(stopC chan struct{}, interval time.Duration) { + site.Health = NewHealth(time.Minute + interval) + loadpointChan := make(chan Updater) go site.loopLoadpoints(loadpointChan)