Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Commit 7967b4b

Browse files
committed
Add RetryTimeout to configuration
Signed-off-by: Leandro López (inkel) <[email protected]>
1 parent 3e5bd17 commit 7967b4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

client.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ type Config struct {
4040
OrgID int64
4141
// NumRetries contains the number of attempted retries
4242
NumRetries int
43+
// RetryTimeout says how long to wait before retrying a request
44+
RetryTimeout time.Duration
4345
}
4446

4547
// New creates a new Grafana client.
@@ -93,7 +95,10 @@ func (c *Client) request(method, requestPath string, query url.Values, bodyRd io
9395

9496
// Wait a bit if that's not the first request
9597
if n != 0 {
96-
time.Sleep(time.Second * 5)
98+
if c.config.RetryTimeout == 0 {
99+
c.config.RetryTimeout = time.Second * 5
100+
}
101+
time.Sleep(c.config.RetryTimeout)
97102
}
98103

99104
resp, err = c.client.Do(req)

client_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http/httptest"
1010
"net/url"
1111
"testing"
12+
"time"
1213
)
1314

1415
func TestNew_basicAuth(t *testing.T) {
@@ -228,8 +229,9 @@ func TestClient_requestWithRetries(t *testing.T) {
228229
}
229230

230231
c, err := New(ts.URL, Config{
231-
NumRetries: 5,
232-
Client: httpClient,
232+
NumRetries: 5,
233+
Client: httpClient,
234+
RetryTimeout: 50 * time.Millisecond,
233235
})
234236
if err != nil {
235237
t.Fatalf("unexpected error creating client: %v", err)

0 commit comments

Comments
 (0)