cmd: add retry/backoff (#10069)

This commit adds retry/backoff to the registry client for pull requests.

Also, revert progress indication to match original client's until we can
"get it right."

Also, make WithTrace wrap existing traces instead of clobbering them.
This allows clients to compose traces.
This commit is contained in:
Blake Mizerany
2025-04-15 23:24:44 -07:00
committed by GitHub
parent ccb7eb8135
commit 1e7f62cb42
6 changed files with 233 additions and 158 deletions

View File

@@ -34,10 +34,27 @@ func (t *Trace) update(l *Layer, n int64, err error) {
type traceKey struct{}
// WithTrace returns a context derived from ctx that uses t to report trace
// events.
// WithTrace adds a trace to the context for transfer progress reporting.
func WithTrace(ctx context.Context, t *Trace) context.Context {
return context.WithValue(ctx, traceKey{}, t)
old := traceFromContext(ctx)
if old == t {
// No change, return the original context. This also prevents
// infinite recursion below, if the caller passes the same
// Trace.
return ctx
}
// Create a new Trace that wraps the old one, if any. If we used the
// same pointer t, we end up with a recursive structure.
composed := &Trace{
Update: func(l *Layer, n int64, err error) {
if old != nil {
old.update(l, n, err)
}
t.update(l, n, err)
},
}
return context.WithValue(ctx, traceKey{}, composed)
}
var emptyTrace = &Trace{}