Files
threshold/internal/db/backoff.go
T
Jim 27b4d7a034 basic internal db interfaces and Gorm implementation
* db reader and writer interfaces which should allow us to encapsulate the vast majority of database code in this package.

* GormReadWriter implementation of the Reader and Writer interfaces
2020-05-05 13:29:47 -04:00

27 lines
488 B
Go

package db
import (
"math"
"math/rand"
"time"
)
type Backoff interface {
Duration(attemptNumber uint) time.Duration
}
type ConstBackoff struct {
DurationMs time.Duration
}
func (b ConstBackoff) Duration(attempt uint) time.Duration {
return time.Millisecond * time.Duration(b.DurationMs)
}
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))
}