Module: Sidekiq::Throttled::Registry

Defined in:
lib/sidekiq/throttled/registry.rb

Overview

Registred strategies.

Class Method Summary collapse

Class Method Details

.add(name, **kwargs) ⇒ Strategy

Note:

prints a warning to STDERR upon duplicate strategy name

Adds strategy to the registry.

Parameters:

Returns:



21
22
23
24
25
26
27
# File 'lib/sidekiq/throttled/registry.rb', line 21

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.

Parameters:

  • new_name (#to_s)
  • old_name (#to_s)

Returns:

Raises:

  • (RuntimeError)

    if no strategy found with `old_name`



36
37
38
39
40
41
42
43
44
# File 'lib/sidekiq/throttled/registry.rb', line 36

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

.eachEnumerator .each {|strategy| ... } ⇒ Registry

Overloads:

  • .eachEnumerator

    Returns:

    • (Enumerator)
  • .each {|strategy| ... } ⇒ Registry

    Yields:

    • (strategy)

      Gives strategy to the block

    Yield Parameters:

    Returns:



69
70
71
72
73
# File 'lib/sidekiq/throttled/registry.rb', line 69

def each
  return to_enum(__method__) unless block_given?
  @strategies.each { |*args| yield(*args) }
  self
end

.each_with_static_keysEnumerator .each_with_static_keys {|strategy| ... } ⇒ Registry

Overloads:

  • .each_with_static_keysEnumerator

    Returns:

    • (Enumerator)
  • .each_with_static_keys {|strategy| ... } ⇒ Registry

    Yields:

    • (strategy)

      Gives strategy to the block

    Yield Parameters:

    Returns:



83
84
85
86
87
88
# File 'lib/sidekiq/throttled/registry.rb', line 83

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

Overloads:

  • .get(name) ⇒ Strategy?

    Returns registred strategy

    Parameters:

    • name (#to_s)

    Returns:

    • (Strategy, nil)

      registred strategy

  • .get(name) {|strategy| ... } ⇒ Object

    Yields control to the block if requested strategy was found.

    Yields:

    • (strategy)

      Gives found strategy to the block

    Yield Parameters:

    Returns:

    • result of a block



55
56
57
58
59
# File 'lib/sidekiq/throttled/registry.rb', line 55

def get(name)
  strategy = @strategies[name.to_s] || @aliases[name.to_s]
  return yield strategy if strategy && block_given?
  strategy
end