fix linter

This commit is contained in:
Pavel 2025-03-18 17:00:42 +03:00
parent 2f33b56cd3
commit e2113a640e
2 changed files with 15 additions and 10 deletions

View File

@ -104,10 +104,11 @@ func (c *Client) executeWithRetry(
res interface{} res interface{}
statusCode int statusCode int
err error err error
lastAttempt bool
attempt uint = 1 attempt uint = 1
maxAttempts = c.limiter.maxAttempts maxAttempts = c.limiter.maxAttempts
totalAttempts = "∞"
infinite = maxAttempts == 0 infinite = maxAttempts == 0
lastAttempt = false
) )
var baseDelay time.Duration var baseDelay time.Duration
@ -117,6 +118,10 @@ func (c *Client) executeWithRetry(
baseDelay = regularDelay baseDelay = regularDelay
} }
if !infinite {
totalAttempts = strconv.FormatUint(uint64(maxAttempts), 10)
}
for infinite || attempt <= maxAttempts { for infinite || attempt <= maxAttempts {
c.applyRateLimit(uri) c.applyRateLimit(uri)
res, statusCode, err = executeFunc() res, statusCode, err = executeFunc()
@ -135,8 +140,8 @@ func (c *Client) executeWithRetry(
// Calculate exponential backoff delay: baseDelay * 2^(attempt-1). // Calculate exponential backoff delay: baseDelay * 2^(attempt-1).
backoffDelay := baseDelay * (1 << (attempt - 1)) backoffDelay := baseDelay * (1 << (attempt - 1))
if c.Debug { if c.Debug {
c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%d)", c.writeLog("API Error: rate limited (503), retrying in %v (attempt %d/%s)",
backoffDelay, attempt, maxAttempts) backoffDelay, attempt, totalAttempts)
} }
time.Sleep(backoffDelay) time.Sleep(backoffDelay)

View File

@ -15,7 +15,7 @@ const ByID = "id"
// ByExternalID is "externalId" constant to use as `by` property in methods. // ByExternalID is "externalId" constant to use as `by` property in methods.
const ByExternalID = "externalId" const ByExternalID = "externalId"
// RateLimiter configuration constants // RateLimiter configuration constants.
const ( const (
regularPathRPS = 10 // API rate limit (requests per second). regularPathRPS = 10 // API rate limit (requests per second).
telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second). telephonyPathRPS = 40 // Telephony API endpoints rate limit (requests per second).