Skip to content

Commit

Permalink
chore: revert "chore: add rate limited http client"
Browse files Browse the repository at this point in the history
This reverts commit 09ee899.
  • Loading branch information
yashasvibajpai committed Nov 6, 2024
1 parent 09ee899 commit b1eaeda
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package klaviyobulkupload
import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
Expand All @@ -13,8 +12,6 @@ import (
"strings"
"time"

"golang.org/x/time/rate"

jsoniter "github.com/json-iterator/go"
"github.com/samber/lo"

Expand All @@ -35,24 +32,6 @@ const (

var json = jsoniter.ConfigCompatibleWithStandardLibrary

func NewRateLimitedClient(burstLimit int, steadyRate float64) *RateLimitedClient {
// burstLimit defines the burst capacity (10 requests per second)
// steadyRate defines the steady state rate (2.5 requests per second, equivalent to 150 requests per minute)
limiter := rate.NewLimiter(rate.Limit(steadyRate), burstLimit)
return &RateLimitedClient{
client: &http.Client{},
limiter: limiter,
}
}

func (rlc *RateLimitedClient) Do(req *http.Request) (*http.Response, error) {
// Wait for permission to proceed.
if err := rlc.limiter.Wait(context.Background()); err != nil {
return nil, err
}
return rlc.client.Do(req)
}

func createFinalPayload(combinedProfiles []Profile, listId string) Payload {
payload := Payload{
Data: Data{
Expand Down Expand Up @@ -381,8 +360,7 @@ func (kbu *KlaviyoBulkUploader) Upload(asyncDestStruct *common.AsyncDestinationS
return kbu.generateKlaviyoErrorOutput("Error while marshaling combined JSON.", err, importingJobIDs, destinationID)
}
uploadURL := KlaviyoAPIURL
// client := &http.Client{}
client := NewRateLimitedClient(10, 2.5)
client := &http.Client{}
req, err := http.NewRequest("POST", uploadURL, bytes.NewBuffer(outputJSON))
if err != nil {
return kbu.generateKlaviyoErrorOutput("Error while creating request.", err, importingJobIDs, destinationID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ import (
"github.com/rudderlabs/rudder-go-kit/stats"

"github.com/rudderlabs/rudder-server/router/batchrouter/asyncdestinationmanager/common"
"golang.org/x/time/rate"
)

type RateLimitedClient struct {
client *http.Client
limiter *rate.Limiter
}

type Uploader interface {
Upload(*common.AsyncDestinationStruct) common.AsyncUploadOutput
}
Expand Down

0 comments on commit b1eaeda

Please sign in to comment.