mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
refactor(control): remove unused functionality
This commit is contained in:
parent
b4c30a482d
commit
f46e5504fc
1 changed files with 0 additions and 33 deletions
|
|
@ -2,7 +2,6 @@ package control
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -30,33 +29,6 @@ func ExponentialBackoffWithLimit(b float64, d time.Duration, limit time.Duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultRetries is a constant for the maximum number of retries we usually do.
|
|
||||||
// However, callers of Retry are free to choose a different number.
|
|
||||||
const DefaultRetries = 5
|
|
||||||
|
|
||||||
type abortErr struct {
|
|
||||||
Err error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e abortErr) Error() string {
|
|
||||||
return e.Err.Error()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e abortErr) Unwrap() error {
|
|
||||||
return e.Err
|
|
||||||
}
|
|
||||||
|
|
||||||
// AbortRetry aborts any further attempts of retrying an operation.
|
|
||||||
//
|
|
||||||
// If err is passed Retry returns the passed error. If nil is passed, Retry
|
|
||||||
// returns nil.
|
|
||||||
func AbortRetry(err error) error {
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return abortErr{Err: err}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retry executes f at most maxTries times.
|
// Retry executes f at most maxTries times.
|
||||||
func Retry(ctx context.Context, maxTries int, f func() error) error {
|
func Retry(ctx context.Context, maxTries int, f func() error) error {
|
||||||
logger := contextlogger.From(ctx)
|
logger := contextlogger.From(ctx)
|
||||||
|
|
@ -70,12 +42,7 @@ func Retry(ctx context.Context, maxTries int, f func() error) error {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
var aerr abortErr
|
|
||||||
|
|
||||||
err = f()
|
err = f()
|
||||||
if errors.As(err, &aerr) {
|
|
||||||
return aerr.Err
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
sleep := backoff(try)
|
sleep := backoff(try)
|
||||||
logger.DebugContext(ctx, "operation failed, waiting before trying again", "try", try, "backoff", sleep)
|
logger.DebugContext(ctx, "operation failed, waiting before trying again", "try", try, "backoff", sleep)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue