Loadpoint: add asleep messaging event if wakeup fails (#23116)
This commit is contained in:
parent
4b0524e392
commit
0f70bb3106
7 changed files with 63 additions and 27 deletions
|
|
@ -7,9 +7,18 @@ import (
|
|||
"github.com/benbjohnson/clock"
|
||||
)
|
||||
|
||||
const wakeupTimeout = 30 * time.Second
|
||||
const (
|
||||
wakeupTimeout = 30 * time.Second
|
||||
wakeupAttempts = 6
|
||||
)
|
||||
|
||||
const wakeupAttempts = 6 // wakeupAttempts is the count of wakeup attempts
|
||||
type WakeUpEvent int
|
||||
|
||||
const (
|
||||
WakeUpTimerInactive WakeUpEvent = iota
|
||||
WakeUpTimerElapsed
|
||||
WakeUpTimerFinished
|
||||
)
|
||||
|
||||
// Timer measures active time between start and stop events
|
||||
type Timer struct {
|
||||
|
|
@ -48,20 +57,22 @@ func (m *Timer) Stop() {
|
|||
m.started = time.Time{}
|
||||
}
|
||||
|
||||
// Expired checks if the timer has elapsed and if resets its status
|
||||
func (m *Timer) Expired() bool {
|
||||
// Elapsed checks if the timer has elapsed and if resets its status
|
||||
func (m *Timer) Elapsed() WakeUpEvent {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
res := !m.started.IsZero() && (m.clck.Since(m.started) >= wakeupTimeout)
|
||||
if res {
|
||||
m.wakeupAttemptsLeft--
|
||||
if m.wakeupAttemptsLeft == 0 {
|
||||
m.started = time.Time{}
|
||||
} else {
|
||||
m.started = m.clck.Now()
|
||||
}
|
||||
if m.started.IsZero() || m.clck.Since(m.started) < wakeupTimeout {
|
||||
return WakeUpTimerInactive
|
||||
}
|
||||
|
||||
return res
|
||||
if m.wakeupAttemptsLeft == 0 {
|
||||
m.started = time.Time{}
|
||||
return WakeUpTimerFinished
|
||||
}
|
||||
|
||||
m.wakeupAttemptsLeft--
|
||||
|
||||
m.started = m.clck.Now()
|
||||
return WakeUpTimerElapsed
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue