recovery

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitBreakerOpen is returned when the circuit breaker is in the open state
	ErrCircuitBreakerOpen = errors.New(errors.InternalErrorCode, "circuit breaker is open")
	// ErrServiceUnavailable is returned when a service is not available
	ErrServiceUnavailable = errors.New(errors.NetworkErrorCode, "service unavailable")
	// ErrContextCanceled is returned when the context is canceled
	ErrContextCanceled = errors.New(errors.CanceledCode, "context canceled")
	// ErrContextDeadlineExceeded is returned when the context deadline is exceeded
	ErrContextDeadlineExceeded = errors.New(errors.TimeoutCode, "context deadline exceeded")
)

Functions

This section is empty.

Types

type CircuitBreaker

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

CircuitBreaker implements the circuit breaker pattern

func NewCircuitBreaker

func NewCircuitBreaker(failureThreshold int, cooldownPeriod time.Duration) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(ctx context.Context, operation func() error) (err error)

Execute executes an operation with circuit breaker protection

func (*CircuitBreaker) ExecuteWithName

func (cb *CircuitBreaker) ExecuteWithName(ctx context.Context, operationName string, operation func() error) (err error)

ExecuteWithName executes an operation with circuit breaker protection and a specific operation name

type RecoveryHandler

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

RecoveryHandler handles panic recovery and error rate limiting

func NewRecoveryHandler

func NewRecoveryHandler(logger *logging.ContextLogger, errorsPerSecond int) *RecoveryHandler

NewRecoveryHandler creates a new recovery handler with error rate limiting

func (*RecoveryHandler) WithRecovery

func (h *RecoveryHandler) WithRecovery(ctx context.Context, operation string, fn func() error) (err error)

WithRecovery wraps an operation with panic recovery and error rate limiting

Jump to

Keyboard shortcuts

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