Documentation
¶
Index ¶
- type CircuitBreaker
- type CircuitState
- type Config
- type Manager
- func (m *Manager) AcquireToken(ctx context.Context) error
- func (m *Manager) Execute(ctx context.Context, resourceName string, fn func() error) error
- func (m *Manager) GetStats() Stats
- func (m *Manager) HealthCheck() error
- func (m *Manager) ResetCircuitBreaker(resourceName string)
- func (m *Manager) RestoreLimit(original float64)
- func (m *Manager) Throttle(factor float64)
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker protects resources from cascading failures
func NewCircuitBreaker ¶
func NewCircuitBreaker(name string, maxFailures int, resetTimeout time.Duration, logger *slog.Logger) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) Call ¶
func (cb *CircuitBreaker) Call(ctx context.Context, fn func() error) error
Call executes the function with circuit breaker protection
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState() CircuitState
GetState returns the current state
func (*CircuitBreaker) Reset ¶
func (cb *CircuitBreaker) Reset()
Reset manually resets the circuit breaker
type CircuitState ¶
type CircuitState int
CircuitState represents the state of a circuit breaker
const ( // StateClosed allows requests to pass through StateClosed CircuitState = iota // StateOpen blocks all requests StateOpen // StateHalfOpen allows limited requests to test recovery StateHalfOpen )
type Config ¶
type Config struct {
// Rate limiting
RequestsPerSecond float64
BurstSize int
// Concurrency
MaxConcurrent int
// Circuit breaker defaults
MaxFailures int
ResetTimeout time.Duration
}
Config holds resource manager configuration
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles resource management including rate limiting, connection pooling, and circuit breaking
func NewManager ¶
NewManager creates a new resource manager
func (*Manager) AcquireToken ¶
AcquireToken waits for rate limiter permission
func (*Manager) HealthCheck ¶
HealthCheck performs a health check on resource manager
func (*Manager) ResetCircuitBreaker ¶
ResetCircuitBreaker manually resets a circuit breaker
func (*Manager) RestoreLimit ¶
RestoreLimit restores original rate limit