persona-community-3/pkg/routing/strategy.go
jordan f53b908499
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/manual/woodpecker Pipeline was successful
Initialize project from skeleton template
2026-02-23 11:10:35 +00:00

46 lines
1.5 KiB
Go

package routing
// Strategy defines how requests are routed to providers.
// Uses kebab-case consistently for JSON/config serialization.
//
// IMPORTANT: Use the constants below, not string literals.
// This enables compile-time checking and refactoring support.
type Strategy string
const (
// StrategyPrimaryOnly uses only the first provider, failing immediately on error.
// Use when you want deterministic behavior with no automatic failover.
// The provider is NOT put in cooldown on failure.
StrategyPrimaryOnly Strategy = "primary-only"
// StrategyFallback tries providers in order until one succeeds.
//
// CRITICAL: The LAST provider in the chain (terminus) is ALWAYS attempted
// regardless of cooldown state. This is the fallback of last resort.
//
// Providers that fail with rate-limit or transient errors enter cooldown
// and will be skipped on subsequent requests until the cooldown expires.
// The terminus never enters cooldown.
StrategyFallback Strategy = "fallback"
// StrategyRoundRobin distributes requests across providers evenly.
// Uses atomic counter to rotate through providers.
// Does NOT respect cooldowns; each call rotates to the next provider.
StrategyRoundRobin Strategy = "round-robin"
)
// Valid returns true if the strategy is recognized.
func (s Strategy) Valid() bool {
switch s {
case StrategyPrimaryOnly, StrategyFallback, StrategyRoundRobin:
return true
default:
return false
}
}
// String returns the strategy value as a string.
func (s Strategy) String() string {
return string(s)
}