Class: Sidekiq::Throttled::Cooldown

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Cooldown

Returns a new instance of Cooldown.

Parameters:



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?

Parameters:

Returns:



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.

Parameters:

  • queue (String)


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.

Parameters:

  • queue (String)


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

#queuesArray<String>

List of queues that should not be polled

Returns:

  • (Array<String>)


50
51
52
# File 'lib/sidekiq/throttled/cooldown.rb', line 50

def queues
  @queues.to_a
end