Class: Sidekiq::Throttled::Cooldown
- Inherits:
-
Object
- Object
- Sidekiq::Throttled::Cooldown
- Defined in:
- lib/sidekiq/throttled/cooldown.rb
Overview
Queues cooldown manager. Tracks list of queues that should be temporarily (for the duration of Sidekiq::Throttled::Config#cooldown_period) excluded from polling.
Class Method Summary collapse
-
.[](config) ⇒ Cooldown?
Returns new Cooldown instance if Sidekiq::Throttled::Config#cooldown_period is not ‘nil`.
Instance Method Summary collapse
-
#initialize(config) ⇒ Cooldown
constructor
A new instance of Cooldown.
-
#notify_admitted(queue) ⇒ void
Notify that given queue returned job that was not throttled.
-
#notify_throttled(queue) ⇒ void
Notify that given queue returned job that was throttled.
-
#queues ⇒ Array<String>
List of queues that should not be polled.
Constructor Details
#initialize(config) ⇒ Cooldown
Returns a new instance of Cooldown.
25 26 27 28 29 |
# File 'lib/sidekiq/throttled/cooldown.rb', line 25 def initialize(config) @queues = ExpirableSet.new(config.cooldown_period) @threshold = config.cooldown_threshold @tracker = Concurrent::Map.new end |
Class Method Details
.[](config) ⇒ Cooldown?
Returns new Sidekiq::Throttled::Cooldown instance if Sidekiq::Throttled::Config#cooldown_period is not ‘nil`.
19 20 21 |
# File 'lib/sidekiq/throttled/cooldown.rb', line 19 def [](config) new(config) if config.cooldown_period end |
Instance Method Details
#notify_admitted(queue) ⇒ void
This method returns an undefined value.
Notify that given queue returned job that was not throttled.
43 44 45 |
# File 'lib/sidekiq/throttled/cooldown.rb', line 43 def notify_admitted(queue) @tracker.delete(queue) end |
#notify_throttled(queue) ⇒ void
This method returns an undefined value.
Notify that given queue returned job that was throttled.
35 36 37 |
# File 'lib/sidekiq/throttled/cooldown.rb', line 35 def notify_throttled(queue) @queues.add(queue) if @threshold <= @tracker.merge_pair(queue, 1, &:succ) end |
#queues ⇒ Array<String>
List of queues that should not be polled
50 51 52 |
# File 'lib/sidekiq/throttled/cooldown.rb', line 50 def queues @queues.to_a end |