コード例 #1
0
// postWithRetry calls post() and retries on HTTP failure
// (response code != 200).
func postWithRetry(hc *http.Client, url string, form url.Values) ([]byte, uint, int, error) {
	backoff := lib.Backoff{}
	for {
		responseBody, gcpErrorCode, httpStatusCode, err := post(hc, url, form)
		if responseBody != nil && httpStatusCode == http.StatusOK {
			return responseBody, gcpErrorCode, httpStatusCode, err
		}

		p, retryAgain := backoff.Pause()
		if !retryAgain {
			log.Debugf("HTTP error %s, retry timeout hit", err, p)
			return responseBody, gcpErrorCode, httpStatusCode, err
		}
		log.Debugf("HTTP error %s, retrying after %s", err, p)
		time.Sleep(p)
	}
}
コード例 #2
0
// getWithRetry calls get() and retries on HTTP failure
// (response code != 200).
func getWithRetry(hc *http.Client, url string) (*http.Response, error) {
	backoff := lib.Backoff{}
	for {
		response, err := get(hc, url)
		if response != nil && response.StatusCode == http.StatusOK {
			return response, err
		}

		p, retryAgain := backoff.Pause()
		if !retryAgain {
			log.Debugf("HTTP error %s, retry timeout hit", err, p)
			return response, err
		}
		log.Debugf("HTTP error %s, retrying after %s", err, p)
		time.Sleep(p)
	}
}
コード例 #3
0
func postWithRetry(url string, data url.Values) (*http.Response, error) {
	backoff := lib.Backoff{}
	for {
		response, err := http.PostForm(url, data)
		if err == nil {
			return response, err
		}
		fmt.Printf("POST to %s failed with error: %s\n", url, err)

		p, retryAgain := backoff.Pause()
		if !retryAgain {
			return response, err
		}
		fmt.Printf("retrying POST to %s in %s\n", url, p)
		time.Sleep(p)
	}
}