mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
fix log with next retry time once max retries are exceeded (#16026)
This commit is contained in:
parent
95b1c0df62
commit
3f302a79b4
3 changed files with 7 additions and 4 deletions
1
orbit/changes/log-time-format
Normal file
1
orbit/changes/log-time-format
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fixed a log timestamp to print the right duration value when a fleet update has exceeded the maximum number of retries.
|
||||
|
|
@ -64,7 +64,7 @@ func (t *LimitedWithCooldown) Do(hash string, fn func() error) error {
|
|||
|
||||
if t.retries[hash] >= t.maxRetries &&
|
||||
time.Since(t.wait[hash]) <= t.cooldown {
|
||||
return &ExcessRetriesError{nextRetry: time.Until(t.wait[hash])}
|
||||
return &ExcessRetriesError{nextRetry: time.Until(t.wait[hash].Add(t.cooldown))}
|
||||
}
|
||||
|
||||
if err := fn(); err != nil {
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ func TestLimitedWithCooldwonDo(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("exceed max retries", func(t *testing.T) {
|
||||
lwc := NewLimitedWithCooldown(3, 1*time.Hour)
|
||||
cooldown := 1 * time.Hour
|
||||
lwc := NewLimitedWithCooldown(3, cooldown)
|
||||
hash := "foo"
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
|
|
@ -64,8 +65,9 @@ func TestLimitedWithCooldwonDo(t *testing.T) {
|
|||
err := lwc.Do(hash, func() error {
|
||||
return nil
|
||||
})
|
||||
var rErr *ExcessRetriesError
|
||||
require.ErrorAs(t, err, &rErr)
|
||||
rErr, ok := err.(*ExcessRetriesError)
|
||||
require.True(t, ok)
|
||||
require.WithinDuration(t, time.Now().Add(cooldown), time.Now().Add(rErr.nextRetry), 1*time.Minute)
|
||||
})
|
||||
|
||||
t.Run("cooldown period", func(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue