Skip to content

Commit

Permalink
Improve tot request code
Browse files Browse the repository at this point in the history
Handling some cases where `err` asignment would not have happened
correctly and the error would have been dropped, as well as using an
exponential backoff and reducing the total number of retries done.

Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
  • Loading branch information
stevekuznetsov committed Feb 15, 2018
1 parent e738b08 commit 933f3a5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions prow/pjutil/jobspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"io/ioutil"
"net/http"
"os"
"path"
"strconv"
"time"

Expand Down Expand Up @@ -63,10 +64,12 @@ func NewJobSpec(spec kube.ProwJobSpec, buildId, prowJobId string) JobSpec {
// to vend build identifier for the job
func GetBuildID(name, totURL string) (string, error) {
var err error
url := totURL + "/vend/" + name
for retries := 0; retries < 60; retries++ {
url := path.Join(totURL, "vend", name)
sleep := 100 * time.Millisecond
for retries := 0; retries < 10; retries++ {
if retries > 0 {
time.Sleep(2 * time.Second)
time.Sleep(sleep)
sleep = sleep * 2
}
var resp *http.Response
resp, err = http.Get(url)
Expand All @@ -75,9 +78,12 @@ func GetBuildID(name, totURL string) (string, error) {
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = fmt.Errorf("got unexpected response from tot: %v", resp.Status)
continue
}
if buf, err := ioutil.ReadAll(resp.Body); err == nil {
var buf []byte
buf, err = ioutil.ReadAll(resp.Body)
if err == nil {
return string(buf), nil
}
return "", err
Expand Down

0 comments on commit 933f3a5

Please sign in to comment.