Documentation
¶
Overview ¶
Package selector implements GitHub App selection based on rate limit headroom.
Index ¶
Constants ¶
const ( // DefaultRetrySeconds is the default retry-after value when no reset time is known. DefaultRetrySeconds = 60 // MinRetrySeconds is the minimum retry-after value returned to clients. MinRetrySeconds = 1 )
Variables ¶
var ( // ErrInvalidRepository is returned when the repository format is invalid. ErrInvalidRepository = errors.New("invalid repository format: expected owner/repo") // ErrNoApps is returned when no GitHub Apps are configured. ErrNoApps = errors.New("apps cannot be empty") // ErrNilStore is returned when a nil store is provided. ErrNilStore = errors.New("store cannot be nil") // ErrStateNotFound is returned when no rate limit state exists for an app. ErrStateNotFound = errors.New("rate limit state not found") // ErrNoMatchingApp is returned when no apps are configured for the target organization. ErrNoMatchingApp = errors.New("no GitHub App configured for organization") )
Functions ¶
This section is empty.
Types ¶
type ExhaustedError ¶
type ExhaustedError struct {
RetryAfter int
}
ExhaustedError is returned when all GitHub Apps are rate-limited.
func (*ExhaustedError) Error ¶
func (e *ExhaustedError) Error() string
Error returns the formatted error message with retry-after duration.
type RateLimitState ¶
RateLimitState tracks the GitHub API rate limit for a single App.
func (*RateLimitState) HasCapacity ¶
func (s *RateLimitState) HasCapacity() bool
HasCapacity returns true when there are remaining API calls available.
func (*RateLimitState) IsExpired ¶
func (s *RateLimitState) IsExpired() bool
IsExpired returns true when the rate limit window has reset.
func (*RateLimitState) IsFresherThan ¶
func (s *RateLimitState) IsFresherThan(other *RateLimitState) bool
IsFresherThan reports whether s represents a more recent observation than other. A state is fresher when it belongs to a newer rate limit window, or to the same window but with lower remaining (more usage observed).
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector chooses among GitHub Apps based on rate limit headroom.
func NewSelector ¶
NewSelector creates a Selector. Returns an error if apps is empty or store is nil.
func (*Selector) RecordUsage ¶
func (s *Selector) RecordUsage(ctx context.Context, clientID string, remaining int, resetAt time.Time) error
RecordUsage updates the rate limit state for an app after an API call.
func (*Selector) RetryAfter ¶
RetryAfter returns the seconds until the earliest app window resets. Clamped to [MinRetrySeconds, DefaultRetrySeconds].
type Store ¶
type Store interface {
// GetState returns the rate limit state for the app, or ErrStateNotFound if absent.
GetState(ctx context.Context, clientID string) (*RateLimitState, error)
// SetState updates the state for the app; stale writes may be ignored by the implementation.
SetState(ctx context.Context, clientID string, state *RateLimitState) error
// GetAllStates returns the current state for all known apps.
GetAllStates(ctx context.Context) (map[string]*RateLimitState, error)
// Close releases resources held by the store.
Close() error
}
Store persists and retrieves GitHub App rate limit states. Implementations must be safe for concurrent use.