module FluShot
The idea here is to do something like this in the code:
… your business layer … FluShot.inject
(:user_profile_fetch)
Define a latency vaccine that you can inject into your business layer and adds a random delay between 1 and 3 seconds.
class Latency < FluShot::Vaccine
label :latency def initialize(params) sleep(rand(params[:max] - params[:min]) + params[:min]) end
end
FluShot.on :user_profile_fetch do
FluShot::Vaccine.use(:latency, {min: 1000, max: 3000})
end
Constants
- VERSION
Public Class Methods
inject(name, params = {}, &block)
click to toggle source
# File lib/flu_shot.rb, line 16 def self.inject(name, params = {}, &block) if !before_filter.call return end Prescription.for(name).each do |prescription| Vaccine.find(prescription[:vaccine]).new(prescription[:params].merge(params)) end # @test _before_init block_given? ? block.call : nil rescue FluShot::Sneeze => sneeze raise sneeze.wrapped_exception rescue # @test _exception_muted block_given? ? block.call : nil end
inject_only_if(&block)
click to toggle source
# File lib/flu_shot.rb, line 38 def self.inject_only_if(&block) Thread.current[:before_filter] = block end
Private Class Methods
_before_init()
click to toggle source
@test
# File lib/flu_shot.rb, line 50 def self._before_init end
_exception_muted()
click to toggle source
@test
# File lib/flu_shot.rb, line 54 def self._exception_muted end
before_filter()
click to toggle source
# File lib/flu_shot.rb, line 44 def self.before_filter Thread.current[:before_filter] ||= Proc.new { true } Thread.current[:before_filter] end