Skip to content

Commit

Permalink
concurrency management reimplemented
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeker12 committed Jul 9, 2024
1 parent 8ddf70d commit 799e33c
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ func (c *Client) requestNoRetries(method, endpoint string, body, out interface{}
func (c *Client) request(ctx context.Context, method, endpoint string, body interface{}) (*http.Response, error) {

// TODO Concurrency - Refactor or remove this
// if c.config.ConcurrencyManagementEnabled {
// _, requestID, err := c.Concurrency.AcquireConcurrencyPermit(ctx)
// if err != nil {
// return nil, c.Logger.Error("Failed to acquire concurrency permit", zap.Error(err))
if c.config.EnableConcurrencyManagement {
_, requestID, err := c.Concurrency.AcquireConcurrencyPermit(ctx)
if err != nil {
return nil, fmt.Errorf("Failed to acquire concurrency permit: %v", err)

// }
}

// defer func() {
// c.Concurrency.ReleaseConcurrencyPermit(requestID)
// }()
defer func() {
c.Concurrency.ReleaseConcurrencyPermit(requestID)
}()

// c.Concurrency.Metrics.Lock.Lock()
// c.Concurrency.Metrics.TotalRequests++
// c.Concurrency.Metrics.Lock.Unlock()
// }
c.Concurrency.Metrics.Lock()
c.Concurrency.Metrics.TotalRequests++
c.Concurrency.Metrics.Unlock()
}

requestData, err := (*c.Integration).PrepRequestBody(body, method, endpoint)
if err != nil {
Expand All @@ -274,7 +274,7 @@ func (c *Client) request(ctx context.Context, method, endpoint string, body inte
req = req.WithContext(ctx)

// TODO Concurrency - Refactor or remove this
// startTime := time.Now()
startTime := time.Now()

resp, err := c.http.Do(req)
if err != nil {
Expand All @@ -283,10 +283,10 @@ func (c *Client) request(ctx context.Context, method, endpoint string, body inte
}

// TODO Concurrency - Refactor or remove this
// if c.config.ConcurrencyManagementEnabled {
// duration := time.Since(startTime)
// c.Concurrency.EvaluateAndAdjustConcurrency(resp, duration)
// }
if c.config.EnableConcurrencyManagement {
duration := time.Since(startTime)
c.Concurrency.EvaluateAndAdjustConcurrency(resp, duration)
}

c.CheckDeprecationHeader(resp)

Expand Down

0 comments on commit 799e33c

Please sign in to comment.