Skip to content

Commit 1c03e75

Browse files
committed
init retry config
1 parent e2855ea commit 1c03e75

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

indexer.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ import (
1717

1818
var batchSize = 500
1919

20-
func ElasticRetries() *httpx.RetryConfig {
21-
// retry settings
22-
count := 5
23-
initialBackoff := 1 * time.Second
20+
var retryConfig *httpx.RetryConfig
21+
22+
func init() {
23+
//setup httpx retry configuration
24+
var retrycount = 5
25+
var initialBackoff = 1 * time.Second
26+
retryConfig = ElasticRetries(initialBackoff, retrycount)
27+
}
28+
29+
func ElasticRetries(initialBackoff time.Duration, count int) *httpx.RetryConfig {
2430
backoffs := make([]time.Duration, count)
2531
backoffs[0] = initialBackoff
2632
for i := 1; i < count; i++ {
@@ -165,7 +171,7 @@ func CleanupIndexes(url string, alias string) error {
165171
func MakeJSONRequest(method string, url string, body string, jsonStruct interface{}) (*http.Response, error) {
166172
req, _ := http.NewRequest(method, url, bytes.NewReader([]byte(body)))
167173
req.Header.Add("Content-Type", "application/json")
168-
resp, err := httpx.Do(http.DefaultClient, req, ElasticRetries(), nil)
174+
resp, err := httpx.Do(http.DefaultClient, req, retryConfig, nil)
169175

170176
l := log.WithField("url", url).WithField("method", method).WithField("request", body)
171177
if err != nil {

0 commit comments

Comments
 (0)