Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for setting the rate limiter on the work queue #505

Merged
merged 1 commit into from
Oct 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/utils/taskqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,19 @@ func (t *PeriodicTaskQueue) worker() {
}
}

// NewPeriodicTaskQueue creates a new task queue with the given sync function.
// The sync function is called for every element inserted into the queue.
// NewPeriodicTaskQueue creates a new task queue with the default rate limiter.
func NewPeriodicTaskQueue(resource string, syncFn func(string) error) *PeriodicTaskQueue {
rl := workqueue.DefaultControllerRateLimiter()
return NewPeriodicTaskQueueWithLimiter(resource, syncFn, rl)
}

// NewPeriodicTaskQueueWithLimiter creates a new task queue with the given sync function
// and rate limiter. The sync function is called for every element inserted into the queue.
func NewPeriodicTaskQueueWithLimiter(resource string, syncFn func(string) error, rl workqueue.RateLimiter) *PeriodicTaskQueue {
return &PeriodicTaskQueue{
resource: resource,
keyFunc: KeyFunc,
queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
queue: workqueue.NewRateLimitingQueue(rl),
sync: syncFn,
workerDone: make(chan struct{}),
}
Expand Down