Class: Sidekiq::Antidote::Remedy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sidekiq/antidote/remedy.rb

Overview

Eventually consistent list of inhibitors. Used by middlewares to avoid hitting Redis on every lookup.

Instance Method Summary collapse

Constructor Details

#initialize(refresh_rate, repository:) ⇒ Remedy

Returns a new instance of Remedy.

Parameters:



15
16
17
18
19
# File 'lib/sidekiq/antidote/remedy.rb', line 15

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<Inhibitor> #each {|inhibitor| ... } ⇒ self

Overloads:

  • #eachEnumerator<Inhibitor>

    Returns:

  • #each {|inhibitor| ... } ⇒ self

    For a block { |inhibitor| … }

    Yield Parameters:

    Returns:

    • (self)


28
29
30
31
32
33
34
35
# File 'lib/sidekiq/antidote/remedy.rb', line 28

def each(&block)
  return to_enum __method__ unless block

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

  self
end

#refresher_running?Boolean

Returns whenever inhibitors list async poller is running.

Returns:

  • (Boolean)


56
57
58
# File 'lib/sidekiq/antidote/remedy.rb', line 56

def refresher_running?
  @refresher.running?
end

#start_refresherself

Starts inhibitors list async poller.

Returns:

  • (self)


40
41
42
43
# File 'lib/sidekiq/antidote/remedy.rb', line 40

def start_refresher
  @refresher.execute
  self
end

#stop_refresherself

Stops inhibitors list async poller.

Returns:

  • (self)


48
49
50
51
# File 'lib/sidekiq/antidote/remedy.rb', line 48

def stop_refresher
  @refresher.shutdown
  self
end