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

Adds strategy to the registry.

Parameters:

  • name (#to_s)
  • concurrency (Hash)

    Concurrency options. See keyword args of Strategy::Concurrency#initialize for details.

  • threshold (Hash)

    Threshold options. See keyword args of Strategy::Threshold#initialize for details.

  • key_suffix (#call)

    Dynamic key suffix generator.

  • observer (#call)

    Process called after throttled.

Returns:



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

def add(name, **kwargs)
  name = name.to_s

  @strategies[name] = Strategy.new(name, **kwargs)
end

.add_alias(new_name, old_name) ⇒ Strategy

Adds alias for existing strategy.

Parameters:

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

Returns:

Raises:

  • (RuntimeError)

    if no strategy found with ‘old_name`



32
33
34
35
36
37
38
39
# File 'lib/sidekiq/throttled/registry.rb', line 32

def add_alias(new_name, old_name)
  new_name = new_name.to_s
  old_name = old_name.to_s

  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:



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

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:



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

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.

    Parameters:

    • name (#to_s)

    Yields:

    • (strategy)

      Gives found strategy to the block

    Yield Parameters:

    Returns:

    • result of a block



51
52
53
54
55
56
57
# File 'lib/sidekiq/throttled/registry.rb', line 51

def get(name)
  strategy = find(name.to_s) || find_by_class(name)

  return yield strategy if strategy && block_given?

  strategy
end