Retry vehicle wake-up if necessary (#11707)

This commit is contained in:
chrissooo 2024-02-23 14:43:33 +01:00 • committed by GitHub
parent d59986cbc3
commit 2f30247115
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 15 deletions

View file

@ -9,11 +9,14 @@ import (
const wakeupTimeout = 30 * time.Second
const wakeupAttempts = 6 // wakeupAttempts is the count of wakeup attempts
// Timer measures active time between start and stop events
type Timer struct {
sync.Mutex
clck clock.Clock
started time.Time
clck clock.Clock
started time.Time
wakeupAttemptsLeft int
}
// NewTimer creates timer that can expire
@ -28,6 +31,8 @@ func (m *Timer) Start() {
m.Lock()
defer m.Unlock()
m.wakeupAttemptsLeft = wakeupAttempts
if !m.started.IsZero() {
return
}
@ -50,7 +55,12 @@ func (m *Timer) Expired() bool {
res := !m.started.IsZero() && (m.clck.Since(m.started) >= wakeupTimeout)
if res {
m.started = time.Time{}
m.wakeupAttemptsLeft--
if m.wakeupAttemptsLeft == 0 {
m.started = time.Time{}
} else {
m.started = m.clck.Now()
}
}
return res