ratelimiter

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateError

type CreateError struct {
	// Err is the error that occurred during creation.
	Err error
	// APIGroup is the API group of the object that failed to be created.
	APIGroup string
	// Kind is the kind of the object that failed to be created.
	Kind string
	// Resource is the object that failed to be created.
	Resource metav1.Object
}

CreateError is used to wrap errors that occur during creation.

func NewCreateError

func NewCreateError(err error, apiGroup, kind string, resource metav1.Object) *CreateError

NewCreateError returns a new CreateError which contains info on the failed creation of a k8s object.

func (*CreateError) Error

func (e *CreateError) Error() string

type Executor

type Executor[T any] interface {
	// Identifier returns the identifier of the executor.
	Identifier() string
	// Execute defines the logic how the work item should be executed.
	Execute(ctx context.Context) error
}

Executor defines how a work item should be processed.

type Metrics

type Metrics struct {
	// Executed is the number of work items that have been processed.
	Executed int
	// Failed is the number of work items that have failed.
	Failed int
	// Succeeded is the number of work items that have succeeded.
	Succeeded int
}

Metrics returns the metrics of the rate limiter.

func (*Metrics) Add

func (m *Metrics) Add(executed, failed, succeeded int)

Add adds the given metrics to the current metrics.

func (*Metrics) String

func (m *Metrics) String() string

type Option

type Option[T any] func(*RateLimiter[T])

func WithLogger

func WithLogger[T any](logger *slog.Logger) Option[T]

type RateLimiter

type RateLimiter[T any] struct {
	// contains filtered or unexported fields
}

RateLimiter is used to limit the rate at which work items are processed.

func New

func New[T any](frequency time.Duration, requests, limit int, executor Executor[T], opts ...Option[T]) *RateLimiter[T]

New creates a new RateLimiter. - frequency: the frequency of the rate limiter. - requests: the number of work items to process per interval. - executor: the executor to use to process the work items. - opts: the options to configure the RateLimiter.

func (*RateLimiter[T]) ErrChan

func (r *RateLimiter[T]) ErrChan() <-chan error

ErrChan returns the channel that should be used to receive errors.

func (*RateLimiter[T]) IsRunning

func (r *RateLimiter[T]) IsRunning() bool

IsRunning returns true if the rate limiter is currently running.

func (*RateLimiter[T]) Metrics

func (r *RateLimiter[T]) Metrics() Metrics

Metrics returns the metrics of the rate limiter.

func (*RateLimiter[T]) Run

func (r *RateLimiter[T]) Run(ctx context.Context)

Run starts the rate limiter.

func (*RateLimiter[T]) Stop

func (r *RateLimiter[T]) Stop()

Stop stops the rate limiter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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