utils

package
v0.0.0-...-7dd96b6 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecordMetrics

func RecordMetrics(instance string, status int, duration time.Duration)

func Retry

func Retry(attempts int, sleep time.Duration, callbackFunc func() error) error

Retry attempts to execute the given callback function a certain number of times, with a delay between each attempt using a simple exponential backoff algorithm that uses a slight jitter to ensure that retries aren't clustered.

If the callback function returns an error, Retry will sleep for a certain duration before attempting to call the callback function again.

Retry will repeat this process until the callback function succeeds or until the maximum number of attempts is reached.

If the maximum number of attempts is reached and the callback function still fails, it returns the last error returned by the callback function.

func RetryStop

func RetryStop(err error) error

RetryStop wraps the given error in a private retryError type and returns it to signal that a retry loop should stop attempting the operation that produced the given error.

func UnmarshalJsonObj

func UnmarshalJsonObj(key string, obj interface{}) (map[string]interface{}, error)

Yaml unmarshal limitation causes nested options objects to be decode as strings with json format ex: `{"foo": "bar"}` UnmarshalJsonObj performs unmarshal of jsons strings

func ValidKeys

func ValidKeys[T any](items []T, f func(T) string) bool

generic function to validate uniqueness across slice of attribute returned by f

Types

type BoundedWaitGroup

type BoundedWaitGroup struct {
	// contains filtered or unexported fields
}

BoundedWaitGroup implements a sized WaitGroup

func NewBoundedWaitGroup

func NewBoundedWaitGroup(cap int) BoundedWaitGroup

NewBoundedWaitGroup initializes a new BoundedWaitGroup

func (*BoundedWaitGroup) Add

func (bwg *BoundedWaitGroup) Add(delta int)

Add performs a WaitGroup Add of a specified delta

func (*BoundedWaitGroup) Done

func (bwg *BoundedWaitGroup) Done()

Done performs a WaitGroup Add of -1

func (*BoundedWaitGroup) Wait

func (bwg *BoundedWaitGroup) Wait()

Wait performs a WaitGroup Wait

Jump to

Keyboard shortcuts

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