Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefLimits = Limits{ Workers: 4, DownloadRetries: 3, Tier2: TierLimit{ Boost: 20, Burst: 3, Retries: 20, }, Tier3: TierLimit{ Boost: 60, Burst: 5, Retries: 3, }, Tier4: TierLimit{ Boost: 10, Burst: 7, Retries: 3, }, Request: RequestLimit{ Conversations: 100, Channels: 100, Replies: 200, }, }
var ErrRetryPlease = errors.New("retry")
ErrRetryPlease should be returned by the callback function to indicate that the call should be retried.
var NoLimits = Limits{ Workers: 4, DownloadRetries: 3, Tier2: noTierLimits, Tier3: noTierLimits, Tier4: noTierLimits, Request: RequestLimit{ Conversations: 100, Channels: 100, Replies: 1000, }, }
NoLimits is setting the limits to high values, effectively disabling them.
var ( // OptErrTranslations is the english translations for the validation // errors. OptErrTranslations ut.Translator )
Functions ¶
func NewLimiter ¶
NewLimiter returns throttler with rateLimit requests per minute. optionally caller may specify the boost
func SetMaxAllowedWaitTime ¶
SetMaxAllowedWaitTime sets the maximum time to wait for a transient error.
func WithRetry ¶
func WithRetry(ctx context.Context, lim *rate.Limiter, maxAttempts int, fn func(ctx context.Context) error) error
WithRetry will run the callback function fn. If the function returns slack.RateLimitedError, it will delay, and then call it again up to maxAttempts times. It will return an error if it runs out of attempts.
Types ¶
type ErrRetryFailed ¶
type ErrRetryFailed struct {
Err error
}
ErrRetryFailed is returned if number of retry attempts exceeded the retry attempts limit and function wasn't able to complete without errors.
func (*ErrRetryFailed) Error ¶
func (e *ErrRetryFailed) Error() string
func (*ErrRetryFailed) Is ¶
func (e *ErrRetryFailed) Is(target error) bool
func (*ErrRetryFailed) Unwrap ¶
func (e *ErrRetryFailed) Unwrap() error
type Limits ¶
type Limits struct {
// number of file-saving workers
Workers int `json:"workers,omitempty" yaml:"workers,omitempty" toml:"workers,omitempty" validate:"gte=1,lte=128"`
// if we get rate limited on file downloads, this is how many times we're
// going to retry
DownloadRetries int `json:"download_retries,omitempty" yaml:"download_retries,omitempty" toml:"download_retries,omitempty"`
// Tier-2 limits
Tier2 TierLimit `json:"tier_2,omitempty" yaml:"tier_2,omitempty" toml:"tier_2,omitempty"`
// Tier-3 limits
Tier3 TierLimit `json:"tier_3,omitempty" yaml:"tier_3,omitempty" toml:"tier_3,omitempty"`
// Tier-4 limits
Tier4 TierLimit `json:"tier_4,omitempty" yaml:"tier_4,omitempty" toml:"tier_4,omitempty"`
// Request Limits
Request RequestLimit `json:"per_request,omitempty" yaml:"per_request,omitempty" toml:"per_request,omitempty"`
}
type RequestLimit ¶
type RequestLimit struct {
// number of messages we get per 1 API request. bigger the number, fewer
// requests, but they become more beefy.
Conversations int `json:"conversations,omitempty" yaml:"conversations,omitempty" validate:"gt=0,lte=100" toml:"conversations,omitempty"`
// number of channels to fetch per 1 API request.
Channels int `json:"channels,omitempty" yaml:"channels,omitempty" validate:"gt=0,lte=1000" toml:"channels,omitempty"`
// number of thread replies per request (slack default: 1000)
Replies int `json:"replies,omitempty" yaml:"replies,omitempty" validate:"gt=0,lte=1000" toml:"replies,omitempty"`
}
RequestLimit defines the limits on the requests that are sent to the API.
type TierLimit ¶
type TierLimit struct {
// Tier limiter boost
Boost uint `json:"boost,omitempty" yaml:"boost,omitempty" toml:"boost,omitempty"`
// Tier limiter burst
Burst uint `json:"burst,omitempty" yaml:"burst,omitempty" validate:"gte=1" toml:"burst,omitempty"`
// Tier retries when getting transient errors, i.e. 429 or 500-599.
Retries int `json:"retries,omitempty" yaml:"retries,omitempty" toml:"retries,omitempty"`
}
TierLimit represents a Slack API Tier limits.