Make health check honor update interval (#2683)

This commit is contained in:
andig 2022-02-23 13:13:10 +01:00 • committed by GitHub
parent aefb6ad976
commit 4382259b6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -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 {

View file

@ -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)