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:



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.

Parameters:

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

Returns:

Raises:

  • (RuntimeError)

    if no strategy found with ‘old_name`



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

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

Overloads:

  • .eachEnumerator

    Returns:

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

    Yields:

    • (strategy)

      Gives strategy to the block

    Yield Parameters:

    Returns:



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_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:



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_keys?
  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



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