Class: Sidekiq::Pauzer::Queues
- Inherits:
-
Object
- Object
- Sidekiq::Pauzer::Queues
- 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
- #each(&block) ⇒ Object
-
#initialize(refresh_rate, repository:) ⇒ Queues
constructor
A new instance of Queues.
- #refresher_running? ⇒ Boolean
-
#start_refresher ⇒ self
Starts paused queues list async poller.
-
#stop_refresher ⇒ self
Stops paused queues list async poller.
Constructor Details
#initialize(refresh_rate, repository:) ⇒ Queues
Returns a new instance of Queues.
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
#each ⇒ Enumerator<String> #each {|queue_name| ... } ⇒ 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
54 55 56 |
# File 'lib/sidekiq/pauzer/queues.rb', line 54 def refresher_running? @refresher.running? end |
#start_refresher ⇒ self
Starts paused queues list async poller.
41 42 43 44 |
# File 'lib/sidekiq/pauzer/queues.rb', line 41 def start_refresher @refresher.execute self end |
#stop_refresher ⇒ self
Stops paused queues list async poller.
49 50 51 52 |
# File 'lib/sidekiq/pauzer/queues.rb', line 49 def stop_refresher @refresher.shutdown self end |