Documentation
¶
Index ¶
- func NormalizeWindow(window time.Duration) time.Duration
- func RetryAfter(now time.Time, window time.Duration) time.Duration
- type Limiter
- type Option
- type Pruner
- type Rule
- func RuleForTask(ctx context.Context, db *gorm.DB, runID, taskID uuid.UUID) (*Rule, bool, error)
- func RuleFromDeclarations(jobAlias string, raw datatypes.JSON, resource string, units int) (*Rule, bool, error)
- func RuleFromRateLimits(jobAlias string, declarations []jobdefschema.RateLimit, resource string, ...) (*Rule, bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NormalizeWindow ¶
NormalizeWindow enforces the minimum one-minute bucket granularity.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter atomically consumes resource units from durable fixed windows.
func NewLimiter ¶
NewLimiter creates a database-backed limiter.
func (*Limiter) Acquire ¶
func (l *Limiter) Acquire(ctx context.Context, resource string, units, limit int, window time.Duration) (bool, error)
Acquire consumes units for resource if the current fixed window has capacity. It is intentionally one guarded raw upsert; GORM's clause.OnConflict cannot express the WHERE guard needed for atomic cross-node rejection.
type Pruner ¶
type Pruner struct {
// contains filtered or unexported fields
}
Pruner deletes expired rate-limit windows.
type Rule ¶
Rule is the resolved rate-limit contract for one task.
func RuleForTask ¶
RuleForTask resolves the persisted task-level rate-limit fields and owning job-level declaration for a task run.
func RuleFromDeclarations ¶
func RuleFromDeclarations(jobAlias string, raw datatypes.JSON, resource string, units int) (*Rule, bool, error)
RuleFromDeclarations resolves a task resource/units pair against serialized job-level metadata.rateLimits declarations.
func RuleFromRateLimits ¶
func RuleFromRateLimits(jobAlias string, declarations []jobdefschema.RateLimit, resource string, units int) (*Rule, bool, error)
RuleFromRateLimits resolves a task resource/units pair against parsed job-level metadata.rateLimits declarations.