ratelimiter

package
v0.1.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Copyright 2019, Oath Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter will rate limit by delaying queue additions by a specified time interval plus the timestamp of a previously added item. For example, if there are 2 queue additions with the delayInterval set to 1 second, the first item will be added after a 1 second sleep, the second will be added after the first item delay along with another 1 second delay interval addition resulting in a 2 second sleep.

func NewRateLimiter

func NewRateLimiter(delayInterval time.Duration) *RateLimiter

NewRateLimiter will return a new rate limiter object to be used with the workqueue

func (*RateLimiter) Forget

func (r *RateLimiter) Forget(item interface{})

Forget removes the failure count for an item

func (*RateLimiter) NumRequeues

func (r *RateLimiter) NumRequeues(item interface{}) int

NumRequeues returns the amount of retries for an item

func (*RateLimiter) When

func (r *RateLimiter) When(item interface{}) time.Duration

When returns the time when the item should be added onto the workqueue. Uses the previously set time to calculate the new sleep interval.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL