network

package
v3.0.0-pre-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefLimits = Limits{
	Workers:         4,
	DownloadRetries: 3,
	Tier2: TierLimit{
		Boost:   20,
		Burst:   3,
		Retries: 20,
	},
	Tier3: TierLimit{
		Boost:   120,
		Burst:   5,
		Retries: 3,
	},
	Tier4: TierLimit{
		Boost:   10,
		Burst:   7,
		Retries: 3,
	},
	Request: RequestLimit{
		Conversations: 100,
		Channels:      100,
		Replies:       200,
	},
}
View Source
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.

View Source
var (

	// OptErrTranslations is the english translations for the validation
	// errors.
	OptErrTranslations ut.Translator
)

Functions

func NewLimiter

func NewLimiter(t Tier, burst uint, boost int) *rate.Limiter

NewLimiter returns throttler with rateLimit requests per minute. optionally caller may specify the boost

func SetMaxAllowedWaitTime

func SetMaxAllowedWaitTime(d time.Duration)

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() 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"`
}

func (*Limits) Apply

func (o *Limits) Apply(other Limits) error

Apply applies differing values from other Options. It only affects API-limits related values.

func (*Limits) Validate

func (o *Limits) Validate() error

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 Tier

type Tier int

Tier represents rate limit Tier: https://api.slack.com/docs/rate-limits

const (
	// base throttling defined in events per minute
	NoTier Tier = 6000 // no Tier is applied

	// Tier1 Tier = 1
	Tier2 Tier = 20
	Tier3 Tier = 50
	Tier4 Tier = 100
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL