mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-02-08 18:57:05 +00:00
refactor: change package names
This commit is contained in:
parent
62578ad5c5
commit
4b77b81689
24 changed files with 167 additions and 155 deletions
28
hcloudimages/backoff/backoff.go
Normal file
28
hcloudimages/backoff/backoff.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package backoff
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/hetznercloud/hcloud-go/v2/hcloud"
|
||||
)
|
||||
|
||||
// From https://github.com/hetznercloud/terraform-provider-hcloud/blob/v1.46.1/internal/control/retry.go
|
||||
// Copyright (c) Hetzner Cloud GmbH
|
||||
|
||||
// ExponentialBackoffWithLimit returns a [hcloud.BackoffFunc] which implements an exponential
|
||||
// backoff.
|
||||
// It uses the formula:
|
||||
//
|
||||
// min(b^retries * d, limit)
|
||||
func ExponentialBackoffWithLimit(b float64, d time.Duration, limit time.Duration) hcloud.BackoffFunc {
|
||||
return func(retries int) time.Duration {
|
||||
current := time.Duration(math.Pow(b, float64(retries))) * d
|
||||
|
||||
if current > limit {
|
||||
return limit
|
||||
} else {
|
||||
return current
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue