Bump next bugle default check time before doing check

This commit is contained in:
Tulir Asokan 2024-04-03 17:56:45 +03:00
parent fcfd04f47c
commit f6a9f7811d
2 changed files with 10 additions and 5 deletions

View file

@ -214,7 +214,9 @@ func (c *Client) handleUpdatesEvent(msg *IncomingRPCMessage) {
c.triggerEvent(&events.GaiaLoggedOut{}) c.triggerEvent(&events.GaiaLoggedOut{})
return return
} }
c.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval) if !msg.IsOld {
c.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval)
}
data, ok := msg.DecryptedMessage.(*gmproto.UpdateEvents) data, ok := msg.DecryptedMessage.(*gmproto.UpdateEvents)
if !ok { if !ok {
c.Logger.Error(). c.Logger.Error().

View file

@ -199,9 +199,8 @@ func (dp *dittoPinger) Loop() {
case <-dp.stop: case <-dp.stop:
return return
} }
if time.Until(dp.client.getNextBugleDefaultCheck()) <= 0 { if dp.client.shouldDoBugleDefaultCheck() {
go dp.BugleDefaultCheck() go dp.BugleDefaultCheck()
dp.client.bumpNextBugleDefaultCheck(DefaultBugleDefaultCheckInterval)
} }
} }
} }
@ -226,10 +225,14 @@ func (dp *dittoPinger) BugleDefaultCheck() {
} }
} }
func (c *Client) getNextBugleDefaultCheck() time.Time { func (c *Client) shouldDoBugleDefaultCheck() bool {
c.nextBugleDefaultCheckLock.Lock() c.nextBugleDefaultCheckLock.Lock()
defer c.nextBugleDefaultCheckLock.Unlock() defer c.nextBugleDefaultCheckLock.Unlock()
return c.nextBugleDefaultCheck if time.Until(c.nextBugleDefaultCheck) <= 0 {
c.nextBugleDefaultCheck = time.Now().Add(DefaultBugleDefaultCheckInterval)
return true
}
return false
} }
func (c *Client) bumpNextBugleDefaultCheck(after time.Duration) { func (c *Client) bumpNextBugleDefaultCheck(after time.Duration) {