Skip to content

Commit 74be6fe

Browse files
authored
Merge pull request #248 from deploymenttheory/dev-jl-version2
Added Features: mandatory req delay, retry mechanism togglable
2 parents e04978c + 8a80fe6 commit 74be6fe

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

httpclient/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ type ClientConfig struct {
4747
FollowRedirects bool `json:"follow_redirects"`
4848
MaxRedirects int `json:"max_redirects"`
4949
EnableConcurrencyManagement bool `json:"enable_concurrency_management"`
50+
MandatoryRequestDelay time.Duration
51+
RetryEligiableRequests bool `json:"retry_eligiable_requests"`
5052
}
5153

5254
// BuildClient creates a new HTTP client with the provided configuration.

httpclient/request.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ import (
6767
func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*http.Response, error) {
6868
log := c.Logger
6969

70+
if !c.config.RetryEligiableRequests {
71+
return c.executeRequest(method, endpoint, body, out)
72+
}
73+
7074
if IsIdempotentHTTPMethod(method) {
7175
return c.executeRequestWithRetries(method, endpoint, body, out)
7276
} else if !IsIdempotentHTTPMethod(method) {
@@ -295,5 +299,7 @@ func (c *Client) doRequest(ctx context.Context, method, endpoint string, body in
295299

296300
c.Logger.Debug("Request sent successfully", zap.String("method", method), zap.String("endpoint", endpoint), zap.Int("status_code", resp.StatusCode))
297301

302+
time.Sleep(c.config.MandatoryRequestDelay)
303+
298304
return resp, nil
299305
}

0 commit comments

Comments
 (0)