From b86c8a6eb30b30986ad6eb82bdf249c9039ba8de Mon Sep 17 00:00:00 2001 From: chlins Date: Thu, 15 May 2025 17:31:03 +0800 Subject: [PATCH] fix: pass the context for retry Signed-off-by: chlins --- pkg/backend/build.go | 4 ++-- pkg/backend/processor/base.go | 2 +- pkg/backend/processor/options.go | 2 +- pkg/backend/pull.go | 6 +++--- pkg/backend/push.go | 6 +++--- pkg/backend/retry.go | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/backend/build.go b/pkg/backend/build.go index 3aa4d646..6193058a 100644 --- a/pkg/backend/build.go +++ b/pkg/backend/build.go @@ -129,7 +129,7 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri }), )) return err - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to build model config: %w", err) } @@ -147,7 +147,7 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri }), )) return err - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to build model manifest: %w", err) } diff --git a/pkg/backend/processor/base.go b/pkg/backend/processor/base.go index f606386a..2dcca78a 100644 --- a/pkg/backend/processor/base.go +++ b/pkg/backend/processor/base.go @@ -124,7 +124,7 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin mu.Unlock() return nil - }, retryOpts...) + }, append(defaultRetryOpts, retry.Context(ctx))...) }) } diff --git a/pkg/backend/processor/options.go b/pkg/backend/processor/options.go index b1cf9a06..92fa81d4 100644 --- a/pkg/backend/processor/options.go +++ b/pkg/backend/processor/options.go @@ -45,7 +45,7 @@ func WithProgressTracker(tracker *pb.ProgressBar) ProcessOption { } } -var retryOpts = []retry.Option{ +var defaultRetryOpts = []retry.Option{ retry.Attempts(3), retry.DelayType(retry.BackOffDelay), retry.Delay(5 * time.Second), diff --git a/pkg/backend/pull.go b/pkg/backend/pull.go index dae288a6..53709e90 100644 --- a/pkg/backend/pull.go +++ b/pkg/backend/pull.go @@ -95,7 +95,7 @@ func (b *backend) Pull(ctx context.Context, target string, cfg *config.Pull) err // call the after hook. cfg.Hooks.AfterPullLayer(layer, err) return err - }, retryOpts...) + }, append(defaultRetryOpts, retry.Context(ctx))...) }) } @@ -112,14 +112,14 @@ func (b *backend) Pull(ctx context.Context, target string, cfg *config.Pull) err // copy the config. if err := retry.Do(func() error { return pullIfNotExist(ctx, pb, internalpb.NormalizePrompt("Pulling config"), src, dst, manifest.Config, repo, tag) - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to pull config to local: %w", err) } // copy the manifest. if err := retry.Do(func() error { return pullIfNotExist(ctx, pb, internalpb.NormalizePrompt("Pulling manifest"), src, dst, manifestDesc, repo, tag) - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to pull manifest to local: %w", err) } diff --git a/pkg/backend/push.go b/pkg/backend/push.go index 7a9f390e..62dea44b 100644 --- a/pkg/backend/push.go +++ b/pkg/backend/push.go @@ -79,7 +79,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err g.Go(func() error { return retry.Do(func() error { return pushIfNotExist(ctx, pb, internalpb.NormalizePrompt("Copying blob"), src, dst, layer, repo, tag) - }, retryOpts...) + }, append(defaultRetryOpts, retry.Context(ctx))...) }) } @@ -90,7 +90,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err // copy the config. if err := retry.Do(func() error { return pushIfNotExist(ctx, pb, internalpb.NormalizePrompt("Copying config"), src, dst, manifest.Config, repo, tag) - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to push config to remote: %w", err) } @@ -102,7 +102,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err Digest: godigest.FromBytes(manifestRaw), Data: manifestRaw, }, repo, tag) - }, retryOpts...); err != nil { + }, append(defaultRetryOpts, retry.Context(ctx))...); err != nil { return fmt.Errorf("failed to push manifest to remote: %w", err) } diff --git a/pkg/backend/retry.go b/pkg/backend/retry.go index 04782830..a3e8270a 100644 --- a/pkg/backend/retry.go +++ b/pkg/backend/retry.go @@ -22,7 +22,7 @@ import ( retry "github.com/avast/retry-go/v4" ) -var retryOpts = []retry.Option{ +var defaultRetryOpts = []retry.Option{ retry.Attempts(3), retry.DelayType(retry.BackOffDelay), retry.Delay(5 * time.Second),