-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make strategies inheritance optional.
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# frozen_string_literal: true | ||
|
||
module Sidekiq | ||
module Throttled | ||
# Configuration holder. | ||
class Configuration | ||
# Class constructor. | ||
def initialize | ||
reset! | ||
end | ||
|
||
# Reset configuration to defaults. | ||
# | ||
# @return [void] | ||
def reset! | ||
@inherit_strategies = false | ||
end | ||
|
||
# Instructs throttler to lookup strategies in parent classes, if there's | ||
# no own strategy: | ||
# | ||
# class Foo | ||
# include Sidekiq::Worker | ||
# include Sidekiq::Worker::Throttled | ||
# | ||
# sidekiq_throttle :concurrency => { :limit => 42 } | ||
# end | ||
# | ||
# class Bar < Foo | ||
# end | ||
# | ||
# By default in the example above, `Bar` won't have throttling options. | ||
# Set this flag to `true` to enable this lookup in initializer, after | ||
# that `Bar` will use `Foo` throttling bucket. | ||
def inherit_strategies=(value) | ||
@inherit_strategies = value ? true : false | ||
end | ||
|
||
# Whenever throttled workers should inherit parent's strategies or not. | ||
# Default: `false`. | ||
# | ||
# @return [Boolean] | ||
def inherit_strategies? | ||
@inherit_strategies | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters