ratelimiter

package
v2.1.67 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistributedRateLimiter

type DistributedRateLimiter interface {
	// TokenBucket returns a token bucket rate limiter.
	TokenBucket(ctx context.Context, capacity int64, per time.Duration) *limiters.TokenBucket
}

DistributedRateLimiter is an interface for a distributed rate limiter.

func NewDistributedRateLimiter

func NewDistributedRateLimiter(rdb redis.UniversalClient, key string) DistributedRateLimiter

NewDistributedRateLimiter creates a new instance of DistributedRateLimiter.

type JobRateLimiter

type JobRateLimiter interface {
	// TakeByClusterID takes a token from the rate limiter by cluster ID, returns the time to wait
	// until the next token is available.
	TakeByClusterID(ctx context.Context, clusterID uint, tokens int64) (time.Duration, error)

	// TakeByClusterIDs takes a token from the rate limiter by cluster IDs, returns the time to wait
	// until the next token is available. If only one cluster is reatcted the limit, return the
	// time to wait.
	TakeByClusterIDs(ctx context.Context, clusterIDs []uint, tokens int64) (time.Duration, error)

	// Serve started job rate limiter server.
	Serve()

	// Stop job rate limiter server.
	Stop()
}

JobRateLimiter is an interface for a job rate limiter.

func NewJobRateLimiter

func NewJobRateLimiter(database *database.Database) (JobRateLimiter, error)

NewJobRateLimiter creates a new instance of JobRateLimiter.

Jump to

Keyboard shortcuts

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