Class: Degrade

Inherits:
Object
  • Object
show all
Defined in:
lib/degrade.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis, options) ⇒ Degrade

Returns a new instance of Degrade.



2
3
4
5
6
7
8
9
10
# File 'lib/degrade.rb', line 2

def initialize(redis, options)
  @redis            = redis
  @name             = options[:name]
  @minimum          = options[:minimum] || 100
  @sample           = options[:sample] || 5000
  @threshold        = options[:threshold] || 0.1
  @errors           = options[:errors] || [StandardError]
  @failure_strategy = options[:failure_strategy]
end

Instance Method Details

#failuresObject



26
27
28
# File 'lib/degrade.rb', line 26

def failures
  @redis.get(failures_key).to_f
end

#performObject



12
13
14
15
16
17
18
19
20
# File 'lib/degrade.rb', line 12

def perform
  begin
    mark_request
    yield
  rescue *@errors => e
    mark_failure
    raise e
  end
end

#requestsObject



22
23
24
# File 'lib/degrade.rb', line 22

def requests
  @redis.get(requests_key).to_f
end