Make health check honor update interval (#2683)
This commit is contained in:
parent
aefb6ad976
commit
4382259b6c
2 changed files with 10 additions and 1 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue