Class: Sidekiq::Pauzer::Queues

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sidekiq/pauzer/queues.rb

Overview

Eventually consistent list of paused queues. Used by Sidekiq fetchers to avoid hitting Redis on every fetch call.

Instance Method Summary collapse

Constructor Details

#initialize(refresh_rate, repository:) ⇒ Queues

Returns a new instance of Queues.

Parameters:



16
17
18
19
20
# File 'lib/sidekiq/pauzer/queues.rb', line 16

def initialize(refresh_rate, repository:)
  @refresher = Concurrent::TimerTask.new(execution_interval: refresh_rate, run_now: true) do
    repository.to_a.freeze
  end
end

Instance Method Details

#eachEnumerator<String> #each {|queue_name| ... } ⇒ self

Overloads:

  • #eachEnumerator<String>

    Returns:

    • (Enumerator<String>)
  • #each {|queue_name| ... } ⇒ self

    For a block { |queue_name| … }

    Yield Parameters:

    • queue_name (String)

    Returns:

    • (self)


29
30
31
32
33
34
35
36
# File 'lib/sidekiq/pauzer/queues.rb', line 29

def each(&block)
  return to_enum __method__ unless block

  start_refresher unless refresher_running?
  @refresher.value&.each(&block)

  self
end

#refresher_running?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/sidekiq/pauzer/queues.rb', line 54

def refresher_running?
  @refresher.running?
end

#start_refresherself

Starts paused queues list async poller.

Returns:

  • (self)


41
42
43
44
# File 'lib/sidekiq/pauzer/queues.rb', line 41

def start_refresher
  @refresher.execute
  self
end

#stop_refresherself

Stops paused queues list async poller.

Returns:

  • (self)


49
50
51
52
# File 'lib/sidekiq/pauzer/queues.rb', line 49

def stop_refresher
  @refresher.shutdown
  self
end