Skip to content

Commit

Permalink
Merge pull request #135 from vsoloviov/retry_logic
Browse files Browse the repository at this point in the history
Retry failed requests and do not exit when a single artifact download…
  • Loading branch information
030 authored Jul 13, 2020
2 parents 3521b74 + a2c5128 commit 7bd7b17
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cli/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (n Nexus3) StoreArtifactsOnDisk(regex string) error {
// unless the metadata.xml is opened first
if !(filepath.Ext(url) == ".md5" || filepath.Ext(url) == ".sha1") {
if err := n.downloadArtifact(downloadURL); err != nil {
return err
log.Error(err)
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion cli/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"errors"
"fmt"
"github.com/hashicorp/go-retryablehttp"
"io/ioutil"
"net/http"
"strconv"
Expand Down Expand Up @@ -40,7 +41,11 @@ func (n Nexus3) request(url string) ([]byte, string, error) {
}

func (n Nexus3) response(req *http.Request) ([]byte, string, error) {
resp, err := http.DefaultClient.Do(req)
retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 5
retryClient.Logger = nil
standardClient := retryClient.StandardClient()
resp, err := standardClient.Do(req)
if err != nil {
return nil, "", err
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/fatih/color v1.7.0 // indirect
github.com/frankban/quicktest v1.4.1 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/hashicorp/go-retryablehttp v0.6.6
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
Expand All @@ -22,6 +23,7 @@ require (
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.2
github.com/stretchr/testify v1.2.2
github.com/svenfuchs/jq v0.0.0-20180603193138-b038733a5990
github.com/thedevsaddam/gojsonq v2.2.0+incompatible
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.6 h1:HJunrbHTDDbBb/ay4kxa1n+dLmttUlnP3V9oNE4hmsM=
github.com/hashicorp/go-retryablehttp v0.6.6/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
Expand Down

0 comments on commit 7bd7b17

Please sign in to comment.