persona-community-1/pkg/mediagen/circuit_breaker.go
jordan 4004f88f4a
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/manual/woodpecker Pipeline was successful
Initialize project from skeleton template
2026-02-23 10:20:59 +00:00

74 lines
2.5 KiB
Go

package mediagen
import (
"time"
"git.threesix.ai/jordan/persona-community-1/pkg/routing"
)
// CircuitBreaker is an alias for routing.CircuitBreaker.
//
// IMPORTANT: All cooldown tracking logic is implemented in pkg/routing.
// Do NOT implement custom cooldown logic here. Use routing.CircuitBreaker
// directly for new code.
//
// This alias is provided for backward compatibility with existing code
// that references mediagen.CircuitBreaker.
type CircuitBreaker = routing.CircuitBreaker
// Cooldown period constants - re-exported from routing for convenience.
const (
// DefaultCooldownPeriod is the cooldown for rate limits and quota errors.
DefaultCooldownPeriod = routing.DefaultCooldownPeriod
// TransientCooldownPeriod is the cooldown for transient server errors (503, 500, etc).
TransientCooldownPeriod = routing.TransientCooldownPeriod
)
// FailureType categorizes errors for cooldown duration selection.
// Re-exported from routing for convenience.
type FailureType = routing.FailureType
// FailureType constants.
const (
FailureTypeNone = routing.FailureTypeNone
FailureTypeRateLimit = routing.FailureTypeRateLimit
FailureTypeTransient = routing.FailureTypeTransient
)
// NewCircuitBreaker creates a new circuit breaker.
//
// IMPORTANT: Prefer using routing.NewCircuitBreaker directly for new code.
// This function is provided for backward compatibility.
func NewCircuitBreaker(cooldown time.Duration) *CircuitBreaker {
return routing.NewCircuitBreaker(cooldown)
}
// NewCircuitBreakerWithTransientCooldown creates a circuit breaker with
// custom cooldown periods for rate limits and transient errors.
func NewCircuitBreakerWithTransientCooldown(rateLimitCooldown, transientCooldown time.Duration) *CircuitBreaker {
return routing.NewCircuitBreakerWithTransientCooldown(rateLimitCooldown, transientCooldown)
}
// ClassifyError determines the failure type for an error.
//
// IMPORTANT: Prefer using routing.ClassifyError directly for new code.
func ClassifyError(err error) FailureType {
return routing.ClassifyError(err)
}
// IsRateLimitOrQuotaError checks if an error indicates rate limiting or quota exhaustion.
func IsRateLimitOrQuotaError(err error) bool {
return routing.IsRateLimitError(err)
}
// IsTransientServerError checks if an error indicates a transient server error (5xx).
func IsTransientServerError(err error) bool {
return routing.IsTransientError(err)
}
// IsCooldownTriggeringError checks if an error should trigger any cooldown.
func IsCooldownTriggeringError(err error) bool {
return routing.IsCooldownTriggeringError(err)
}