Skip to content

Commit

Permalink
Fix RedisProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
joel committed Mar 2, 2017
1 parent 84be6bf commit 2d48dff
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions airbrake_proxy.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "airbrake", "~> 5.6"
spec.add_development_dependency "activesupport", "~> 4.2"
spec.add_development_dependency "time_constants", "~> 0.2"
spec.add_development_dependency "redis", "~> 3.3"
end
1 change: 0 additions & 1 deletion lib/airbrake_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,4 @@ def mark_as_notify(key)
def logger
@logger ||= AirbrakeProxy.configuration.logger
end

end
3 changes: 1 addition & 2 deletions lib/airbrake_proxy/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module AirbrakeProxy
module Configure

attr_writer :configuration
attr_reader :configuration

def configuration
@configuration ||= Configuration.new
Expand All @@ -12,6 +12,5 @@ def configuration
def configure
yield(configuration)
end

end
end
10 changes: 8 additions & 2 deletions lib/airbrake_proxy/redis_proxy.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'redis'

module RedisProxy
extend self

Expand All @@ -7,10 +9,10 @@ def method_missing method, *args
redis.send method, *args
rescue Redis::TimeoutError, Redis::CannotConnectError
if (tries += 1) < 10
Rails.logger.warn '[RedisProxy] Retry a Redis call'
logger.warn '[RedisProxy] Retry a Redis call'
retry
else
Rails.logger.warn '[RedisProxy] Fail a Redis call after 10 tries'
logger.warn '[RedisProxy] Fail a Redis call after 10 tries'
raise
end
end
Expand All @@ -21,4 +23,8 @@ def method_missing method, *args
def redis
@redis ||= AirbrakeProxy.configuration.redis
end

def logger
@logger ||= AirbrakeProxy.configuration.logger
end
end
2 changes: 1 addition & 1 deletion lib/airbrake_proxy/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module AirbrakeProxy
VERSION = "0.1.0"
VERSION = "0.1.1"
end
30 changes: 30 additions & 0 deletions spec/lib/redis_proxy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'spec_helper'

module AirbrakeProxy
describe RedisProxy do

subject { RedisProxy }

describe 'keys' do
let(:keys) { [:keys] }

it 'forwards its calls to Redis' do
expect(redis).to receive(:keys).and_return keys
expect(subject.keys).to eql(keys)
end

context 'Redis::TimeoutError' do
it 'should retry 3 times the call to redis' do
expect(redis).to receive(:keys).exactly(10).times.and_raise(::Redis::TimeoutError)
expect { subject.keys }.to raise_error(::Redis::TimeoutError)
end
end
end

private

def redis
@redis ||= AirbrakeProxy.configuration.redis
end
end
end

0 comments on commit 2d48dff

Please sign in to comment.