d28f005552
Fix limit for databases other than sqlite go mod tidy && go mod vendor Remove unneeded break statements Make everything work with the new xorm version Fix xorm logging Fix lint Fix redis init Fix using id field Fix database init for testing Change default database log level Add xorm logger Use const for postgres go mod tidy Merge branch 'master' into update/xorm # Conflicts: # go.mod # go.sum # vendor/modules.txt go mod vendor Fix loading fixtures for postgres Go mod vendor1 Update xorm to version 1 Co-authored-by: kolaente <k@knt.li> Reviewed-on: https://kolaente.dev/vikunja/api/pulls/323
24 lines
513 B
Go
24 lines
513 B
Go
package internal
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// Retry backoff with jitter sleep to prevent overloaded conditions during intervals
|
|
// https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration {
|
|
if retry < 0 {
|
|
retry = 0
|
|
}
|
|
|
|
backoff := minBackoff << uint(retry)
|
|
if backoff > maxBackoff || backoff < minBackoff {
|
|
backoff = maxBackoff
|
|
}
|
|
|
|
if backoff == 0 {
|
|
return 0
|
|
}
|
|
return time.Duration(rand.Int63n(int64(backoff)))
|
|
}
|