Send event when ditto ping stops failing
This commit is contained in:
parent
6c98afb0cc
commit
e6f9c36d87
1 changed files with 7 additions and 0 deletions
|
@ -25,12 +25,18 @@ const phoneNotRespondingTimeout = 30 * time.Second
|
||||||
|
|
||||||
func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) {
|
func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) {
|
||||||
notResponding := false
|
notResponding := false
|
||||||
|
pingFailed := false
|
||||||
exit := false
|
exit := false
|
||||||
onRespond := func() {
|
onRespond := func() {
|
||||||
if notResponding {
|
if notResponding {
|
||||||
log.Debug().Msg("Ditto ping succeeded, phone is back online")
|
log.Debug().Msg("Ditto ping succeeded, phone is back online")
|
||||||
c.triggerEvent(&events.PhoneRespondingAgain{})
|
c.triggerEvent(&events.PhoneRespondingAgain{})
|
||||||
notResponding = false
|
notResponding = false
|
||||||
|
pingFailed = false
|
||||||
|
} else if pingFailed {
|
||||||
|
// TODO separate event?
|
||||||
|
c.triggerEvent(&events.PhoneRespondingAgain{})
|
||||||
|
pingFailed = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doPing := func() {
|
doPing := func() {
|
||||||
|
@ -40,6 +46,7 @@ func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, s
|
||||||
c.triggerEvent(&events.PingFailed{
|
c.triggerEvent(&events.PingFailed{
|
||||||
Error: fmt.Errorf("failed to notify ditto activity: %w", err),
|
Error: fmt.Errorf("failed to notify ditto activity: %w", err),
|
||||||
})
|
})
|
||||||
|
pingFailed = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
|
|
Loading…
Reference in a new issue