Module: Sidekiq::Throttled::Registry
- Defined in:
- lib/sidekiq/throttled/registry.rb
Overview
Registred strategies.
Class Method Summary collapse
-
.add(name, **kwargs) ⇒ Strategy
Adds strategy to the registry.
-
.add_alias(new_name, old_name) ⇒ Strategy
Adds alias for existing strategy.
- .each ⇒ Object
- .each_with_static_keys ⇒ Object
- .get(name) ⇒ Object
Class Method Details
.add(name, **kwargs) ⇒ Strategy
Note:
prints a warning to STDERR upon duplicate strategy name
Adds strategy to the registry.
18 19 20 21 22 23 24 |
# File 'lib/sidekiq/throttled/registry.rb', line 18 def add(name, **kwargs) name = name.to_s warn "Duplicate strategy name: #{name}" if @strategies[name] @strategies[name] = Strategy.new(name, **kwargs) end |
.add_alias(new_name, old_name) ⇒ Strategy
Note:
prints a warning to STDERR upon duplicate strategy name
Adds alias for existing strategy.
33 34 35 36 37 38 39 40 41 |
# File 'lib/sidekiq/throttled/registry.rb', line 33 def add_alias(new_name, old_name) new_name = new_name.to_s old_name = old_name.to_s warn "Duplicate strategy name: #{new_name}" if @strategies[new_name] raise "Strategy not found: #{old_name}" unless @strategies[old_name] @aliases[new_name] = @strategies[old_name] end |
.each ⇒ Enumerator .each {|strategy| ... } ⇒ Registry
66 67 68 69 70 |
# File 'lib/sidekiq/throttled/registry.rb', line 66 def each return to_enum(__method__) unless block_given? @strategies.each { |*args| yield(*args) } self end |
.each_with_static_keys ⇒ Enumerator .each_with_static_keys {|strategy| ... } ⇒ Registry
80 81 82 83 84 85 |
# File 'lib/sidekiq/throttled/registry.rb', line 80 def each_with_static_keys return to_enum(__method__) unless block_given? @strategies.each do |name, strategy| yield(name, strategy) unless strategy.dynamic? end end |
.get(name) ⇒ Strategy? .get(name) {|strategy| ... } ⇒ Object
52 53 54 55 56 |
# File 'lib/sidekiq/throttled/registry.rb', line 52 def get(name) strategy = @strategies[name.to_s] || @aliases[name.to_s] return yield strategy if strategy && block_given? strategy end |