MCPcopy
hub / github.com/aquasecurity/trivy / Retry

Function Retry

pkg/rpc/retry.go:18–45  ·  view source on GitHub ↗

Retry executes the function again using backoff until maxRetries or success

(ctx context.Context, f func() (T, error))

Source from the content-addressed store, hash-verified

16
17// Retry executes the function again using backoff until maxRetries or success
18func Retry[T any](ctx context.Context, f func() (T, error)) (T, error) {
19 operation := func() (T, error) {
20 res, err := f()
21 if err != nil {
22 var zero T
23 twerr, ok := err.(twirp.Error)
24 if !ok {
25 return zero, backoff.Permanent(err)
26 }
27 if twerr.Code() == twirp.Unavailable {
28 return zero, err
29 }
30 return zero, backoff.Permanent(err)
31 }
32 return res, nil
33 }
34
35 return backoff.Retry(
36 ctx,
37 operation,
38 backoff.WithBackOff(backoff.NewExponentialBackOff()),
39 backoff.WithMaxTries(maxRetries),
40 backoff.WithNotify(func(err error, _ time.Duration) {
41 log.Warn("HTTP error", log.Err(err))
42 log.Info("Retrying HTTP request...")
43 }),
44 )
45}

Callers 4

PutArtifactMethod · 0.92
PutBlobMethod · 0.92
MissingBlobsMethod · 0.92
DeleteBlobsMethod · 0.92

Calls 3

ErrFunction · 0.92
InfoMethod · 0.80
CodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…