Class: Sidekiq::Antidote::Remedy
- Inherits:
-
Object
- Object
- Sidekiq::Antidote::Remedy
- 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
- #each(&block) ⇒ Object
-
#initialize(refresh_rate, repository:) ⇒ Remedy
constructor
A new instance of Remedy.
-
#refresher_running? ⇒ Boolean
Returns whenever inhibitors list async poller is running.
-
#start_refresher ⇒ self
Starts inhibitors list async poller.
-
#stop_refresher ⇒ self
Stops inhibitors list async poller.
Constructor Details
#initialize(refresh_rate, repository:) ⇒ Remedy
Returns a new instance of Remedy.
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
#each ⇒ Enumerator<Inhibitor> #each {|inhibitor| ... } ⇒ 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.
56 57 58 |
# File 'lib/sidekiq/antidote/remedy.rb', line 56 def refresher_running? @refresher.running? end |
#start_refresher ⇒ self
Starts inhibitors list async poller.
40 41 42 43 |
# File 'lib/sidekiq/antidote/remedy.rb', line 40 def start_refresher @refresher.execute self end |
#stop_refresher ⇒ self
Stops inhibitors list async poller.
48 49 50 51 |
# File 'lib/sidekiq/antidote/remedy.rb', line 48 def stop_refresher @refresher.shutdown self end |