Merge pull request #884 from bhandras/notification-no-busy-wait

notifications: do not hog the CPU if there's no L402 token yet
This commit is contained in:
András Bánki-Horváth 2025-02-07 12:27:46 +01:00 committed by GitHub
commit c8546d90b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -149,6 +149,7 @@ func (m *Manager) Run(ctx context.Context) error {
waitTime time.Duration
backoff time.Duration
attempts int
timer = time.NewTimer(0)
)
// Start the notification runloop.
@ -156,7 +157,9 @@ func (m *Manager) Run(ctx context.Context) error {
// Increase the wait time for the next iteration.
backoff = waitTime + time.Duration(attempts)*time.Second
waitTime = 0
timer := time.NewTimer(backoff)
// Reset the timer with the new backoff time.
timer.Reset(backoff)
// Return if the context has been canceled.
select {
@ -179,6 +182,10 @@ func (m *Manager) Run(ctx context.Context) error {
log.Errorf("Error getting L402 from "+
"the store: %v", err)
}
// Use a default of 1 second wait time to avoid
// hogging the CPU.
waitTime = time.Second
continue
}