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

#eachObject

Iterates each strategy in collection

Parameters:

  • block (#call)


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

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

#finalize!void

This method returns an undefined value.

Marks job as being processed.



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

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

#reset!void

This method returns an undefined value.

Resets count of jobs of all avaliable strategies



57
58
59
# File 'lib/sidekiq/throttled/strategy_collection.rb', line 57

def reset!
  each(&:reset!)
end

#retry_in(*args) ⇒ Float

Returns How long, in seconds, before we’ll next be able to take on jobs.

Returns:

  • (Float)

    How long, in seconds, before we’ll next be able to take on jobs



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

def retry_in(*args)
  max { |s| s.retry_in(*args) }
end

#throttled?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?(...)
  any? { |s| s.throttled?(...) }
end