mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-03-21 23:33:49 +03:00
fix linter
This commit is contained in:
parent
2f33b56cd3
commit
e2113a640e
11
client.go
11
client.go
@ -104,10 +104,11 @@ func (c *Client) executeWithRetry(
|
||||
res interface{}
|
||||
statusCode int
|
||||
err error
|
||||
lastAttempt bool
|
||||
attempt uint = 1
|
||||
maxAttempts = c.limiter.maxAttempts
|
||||
totalAttempts = "∞"
|
||||
infinite = maxAttempts == 0
|
||||
lastAttempt = false
|
||||
)
|
||||
|
||||
var baseDelay time.Duration
|
||||
@ -117,6 +118,10 @@ func (c *Client) executeWithRetry(
|
||||
baseDelay = regularDelay
|
||||
}
|
||||
|
||||
if !infinite {
|
||||
totalAttempts = strconv.FormatUint(uint64(maxAttempts), 10)
|
||||
}
|
||||
|
||||
for infinite || attempt <= maxAttempts {
|
||||
c.applyRateLimit(uri)
|
||||
res, statusCode, err = executeFunc()
|
||||
@ -135,8 +140,8 @@ func (c *Client) executeWithRetry(
|
||||
// Calculate exponential backoff delay: baseDelay * 2^(attempt-1).
|
||||
backoffDelay := baseDelay * (1 << (attempt - 1))
|
||||
if c.Debug {
|
||||
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%d)",
|
||||
backoffDelay, attempt, maxAttempts)
|
||||
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%s)",
|
||||
backoffDelay, attempt, totalAttempts)
|
||||
}
|
||||
|
||||
time.Sleep(backoffDelay)
|
||||
|
2
types.go
2
types.go
@ -15,7 +15,7 @@ const ByID = "id"
|
||||
// ByExternalID is "externalId" constant to use as `by` property in methods.
|
||||
const ByExternalID = "externalId"
|
||||
|
||||
// RateLimiter configuration constants
|
||||
// RateLimiter configuration constants.
|
||||
const (
|
||||
regularPathRPS = 10 // API rate limit (requests per second).
|
||||
telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).
|
||||
|
Loading…
x
Reference in New Issue
Block a user