Files
threshold/internal/db/backoff.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
551 B
Go
Raw Normal View History

2023-02-02 17:15:17 -08:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package db
import (
"math"
"math/rand"
"time"
)
type Backoff interface {
Duration(attemptNumber uint) time.Duration
}
type ConstBackoff struct {
2024-02-13 10:54:48 -05:00
Amount time.Duration
}
func (b ConstBackoff) Duration(attempt uint) time.Duration {
2024-02-13 10:54:48 -05:00
return time.Millisecond * time.Duration(b.Amount)
}
type ExpBackoff struct{}
func (b ExpBackoff) Duration(attempt uint) time.Duration {
r := rand.Float64()
return time.Millisecond * time.Duration(math.Exp2(float64(attempt))*5*(r+0.5))
}