Skip to content

Commit f2824a1

Browse files
authored
fix: pass the context for retry (#180)
Signed-off-by: chlins <[email protected]>
1 parent 8fc578f commit f2824a1

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

pkg/backend/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri
129129
}),
130130
))
131131
return err
132-
}, retryOpts...); err != nil {
132+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
133133
return fmt.Errorf("failed to build model config: %w", err)
134134
}
135135

@@ -147,7 +147,7 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri
147147
}),
148148
))
149149
return err
150-
}, retryOpts...); err != nil {
150+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
151151
return fmt.Errorf("failed to build model manifest: %w", err)
152152
}
153153

pkg/backend/processor/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (b *base) Process(ctx context.Context, builder build.Builder, workDir strin
124124
mu.Unlock()
125125

126126
return nil
127-
}, retryOpts...)
127+
}, append(defaultRetryOpts, retry.Context(ctx))...)
128128
})
129129
}
130130

pkg/backend/processor/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func WithProgressTracker(tracker *pb.ProgressBar) ProcessOption {
4545
}
4646
}
4747

48-
var retryOpts = []retry.Option{
48+
var defaultRetryOpts = []retry.Option{
4949
retry.Attempts(3),
5050
retry.DelayType(retry.BackOffDelay),
5151
retry.Delay(5 * time.Second),

pkg/backend/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (b *backend) Pull(ctx context.Context, target string, cfg *config.Pull) err
9595
// call the after hook.
9696
cfg.Hooks.AfterPullLayer(layer, err)
9797
return err
98-
}, retryOpts...)
98+
}, append(defaultRetryOpts, retry.Context(ctx))...)
9999
})
100100
}
101101

@@ -112,14 +112,14 @@ func (b *backend) Pull(ctx context.Context, target string, cfg *config.Pull) err
112112
// copy the config.
113113
if err := retry.Do(func() error {
114114
return pullIfNotExist(ctx, pb, internalpb.NormalizePrompt("Pulling config"), src, dst, manifest.Config, repo, tag)
115-
}, retryOpts...); err != nil {
115+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
116116
return fmt.Errorf("failed to pull config to local: %w", err)
117117
}
118118

119119
// copy the manifest.
120120
if err := retry.Do(func() error {
121121
return pullIfNotExist(ctx, pb, internalpb.NormalizePrompt("Pulling manifest"), src, dst, manifestDesc, repo, tag)
122-
}, retryOpts...); err != nil {
122+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
123123
return fmt.Errorf("failed to pull manifest to local: %w", err)
124124
}
125125

pkg/backend/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err
7979
g.Go(func() error {
8080
return retry.Do(func() error {
8181
return pushIfNotExist(ctx, pb, internalpb.NormalizePrompt("Copying blob"), src, dst, layer, repo, tag)
82-
}, retryOpts...)
82+
}, append(defaultRetryOpts, retry.Context(ctx))...)
8383
})
8484
}
8585

@@ -90,7 +90,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err
9090
// copy the config.
9191
if err := retry.Do(func() error {
9292
return pushIfNotExist(ctx, pb, internalpb.NormalizePrompt("Copying config"), src, dst, manifest.Config, repo, tag)
93-
}, retryOpts...); err != nil {
93+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
9494
return fmt.Errorf("failed to push config to remote: %w", err)
9595
}
9696

@@ -102,7 +102,7 @@ func (b *backend) Push(ctx context.Context, target string, cfg *config.Push) err
102102
Digest: godigest.FromBytes(manifestRaw),
103103
Data: manifestRaw,
104104
}, repo, tag)
105-
}, retryOpts...); err != nil {
105+
}, append(defaultRetryOpts, retry.Context(ctx))...); err != nil {
106106
return fmt.Errorf("failed to push manifest to remote: %w", err)
107107
}
108108

pkg/backend/retry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
retry "github.com/avast/retry-go/v4"
2323
)
2424

25-
var retryOpts = []retry.Option{
25+
var defaultRetryOpts = []retry.Option{
2626
retry.Attempts(3),
2727
retry.DelayType(retry.BackOffDelay),
2828
retry.Delay(5 * time.Second),

0 commit comments

Comments
 (0)