Class: Sidekiq::Throttled::StrategyCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sidekiq/throttled/strategy_collection.rb

Overview

Collection which transparently group several meta-strategies of one kind

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategies, strategy:, name:, key_suffix:) ⇒ StrategyCollection

Returns a new instance of StrategyCollection.

Parameters:



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

def initialize(strategies, strategy:, name:, key_suffix:)
  @strategies = (strategies.is_a?(Hash) ? [strategies] : Array(strategies)).map do |options|
    make_strategy(strategy, name, key_suffix, options)
  end
end

Instance Attribute Details

#strategiesObject (readonly)

Returns the value of attribute strategies.



12
13
14
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 12

def strategies
  @strategies
end

Instance Method Details

#dynamic?Boolean

Returns whenever any strategy in collection has dynamic config.

Returns:

  • (Boolean)

    whenever any strategy in collection has dynamic config



34
35
36
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 34

def dynamic?
  any?(&:dynamic?)
end

#each(&block) ⇒ Object

Iterates each strategy in collection

Parameters:

  • block (#call)


29
30
31
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 29

def each(&block)
  @strategies.each(&block)
end

#finalize!(*args) ⇒ void

This method returns an undefined value.

Marks job as being processed.



46
47
48
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 46

def finalize!(*args)
  each { |c| c.finalize!(*args) }
end

#reset!void

This method returns an undefined value.

Resets count of jobs of all avaliable strategies



52
53
54
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 52

def reset!
  each(&:reset!)
end

#throttled?(*args) ⇒ Boolean

by any strategy in collection.

Returns:

  • (Boolean)

    whenever job is throttled or not



40
41
42
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 40

def throttled?(*args)
  any? { |s| s.throttled?(*args) }
end