retry

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, config Config, fn RetryableFunc) error

Do executes a function with retry logic

func DoWithResult

func DoWithResult[T any](ctx context.Context, config Config, fn RetryableFuncWithResult[T]) (T, error)

DoWithResult executes a function with retry logic and returns a result

func IsRetryableError

func IsRetryableError(err error) bool

IsRetryableError checks if an error is retryable

Types

type Config

type Config struct {
	MaxAttempts int               // Maximum number of retry attempts
	BaseDelay   time.Duration     // Base delay between retries
	MaxDelay    time.Duration     // Maximum delay between retries
	Multiplier  float64           // Multiplier for exponential backoff
	Jitter      bool              // Add random jitter to delays
	RetryOn     []types.ErrorType // Error types to retry on
}

Config holds retry configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a sensible default retry configuration

func ServiceNowRetryConfig

func ServiceNowRetryConfig() Config

ServiceNowRetryConfig returns retry configuration optimized for ServiceNow API

type RetryableError

type RetryableError struct {
	Err error
}

RetryableError wraps an error to indicate it should be retried

func NewRetryableError

func NewRetryableError(err error) *RetryableError

NewRetryableError creates a new retryable error

func (*RetryableError) Error

func (r *RetryableError) Error() string

func (*RetryableError) Unwrap

func (r *RetryableError) Unwrap() error

type RetryableFunc

type RetryableFunc func() error

RetryableFunc is a function that can be retried

type RetryableFuncWithResult

type RetryableFuncWithResult[T any] func() (T, error)

RetryableFuncWithResult is a function that returns a result and can be retried

Jump to

Keyboard shortcuts

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