Retry fetching Travis CI logs

This commit is contained in:
Zero King
2019-01-05 17:29:37 +00:00
parent 80c887b233
commit 6710b2dffb
3 changed files with 7 additions and 4 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import (
"net/url"
"os"
"github.com/hashicorp/go-retryablehttp"
retryablehttp "github.com/hashicorp/go-retryablehttp"
)
var pasteURL = &url.URL{
+3
View File
@@ -18,6 +18,7 @@ import (
"sync"
"time"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/macports/mpbot-github/pr/db"
"github.com/macports/mpbot-github/pr/githubapi"
)
@@ -27,6 +28,7 @@ type Receiver struct {
hookSecret []byte
production bool
testing bool
httpClient *retryablehttp.Client
githubClient githubapi.Client
dbHelper db.DBHelper
wg sync.WaitGroup
@@ -41,6 +43,7 @@ func NewReceiver(listenAddr string, hookSecret []byte, botSecret string, product
server: &http.Server{Addr: listenAddr},
hookSecret: hookSecret,
production: production,
httpClient: retryablehttp.NewClient(),
githubClient: githubapi.NewClient(botSecret),
dbHelper: dbHelper,
}
+3 -3
View File
@@ -6,11 +6,11 @@ import (
"io/ioutil"
"log"
"mime/multipart"
"net/http"
"regexp"
"strconv"
"strings"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/macports/mpbot-github/ci/logger/constants"
)
@@ -77,7 +77,7 @@ func (receiver *Receiver) handleTravisWebhook(payload TravisWebhookPayload) {
log.Println("Processing " + strconv.Itoa(len(payload.Matrix)) + " job(s)")
for _, job := range payload.Matrix {
req, err := http.NewRequest(
req, err := retryablehttp.NewRequest(
"GET",
"https://api.travis-ci.org/job/"+strconv.Itoa(job.ID)+"/log",
nil,
@@ -91,7 +91,7 @@ func (receiver *Receiver) handleTravisWebhook(payload TravisWebhookPayload) {
log.Println("Fetching logs for job #" + strconv.Itoa(job.ID))
resp, err := http.DefaultClient.Do(req)
resp, err := receiver.httpClient.Do(req)
if err != nil {
continue
}