Skip to content

Commit

Permalink
Add retry to DownloadPackage (#5017)
Browse files Browse the repository at this point in the history
* Add retry to DownloadPackage.

* Fix missing ()
  • Loading branch information
blakerouse authored Jul 1, 2024
1 parent 09a2a83 commit 1622730
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/testing/fetcher_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ func findLatestSnapshot(ctx context.Context, doer httpDoer, version string) (bui
}

func DownloadPackage(ctx context.Context, l Logger, doer httpDoer, downloadPath string, packageFile string) error {
for i := 0; i < 3; i++ {
err := func() error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Minute)
defer cancel()
return downloadPackage(ctx, l, doer, downloadPath, packageFile)
}()
if err == nil {
return nil
}
l.Logf("Download artifact from %s failed: %s", downloadPath, err)
}
return fmt.Errorf("downloading package failed after 3 retries")
}

func downloadPackage(ctx context.Context, l Logger, doer httpDoer, downloadPath string, packageFile string) error {
l.Logf("Downloading artifact from %s", downloadPath)

req, err := http.NewRequestWithContext(ctx, "GET", downloadPath, nil)
Expand Down

0 comments on commit 1622730

Please sign in to comment.