Skip to content
Browse files

back to a green build - also moving network retry settings into this gem

  • Loading branch information...
1 parent d2b6a7e commit d79d1fb06195a61d6204c53e4545205c96bb6c7e @markburns markburns committed Dec 12, 2012
View
2 Gemfile.lock
@@ -3,6 +3,7 @@ PATH
specs:
shutl_auth (0.0.1)
rack-oauth2
+ retriable
GEM
remote: https://rubygems.org/
@@ -33,6 +34,7 @@ GEM
i18n
multi_json (>= 1.3.6)
rack (>= 1.1)
+ retriable (1.3.3)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
View
2 lib/shutl_auth.rb
@@ -1,5 +1,7 @@
require "shutl_auth/version"
require "rack/oauth2"
+require "retriable/no_kernel"
+require "shutl_auth/network_retry_settings"
require "shutl_auth/access_token_request"
require "shutl_auth/authentication"
View
3 lib/shutl_auth/access_token_request.rb
@@ -22,8 +22,7 @@ def access_token!
private
def uri
- #TODO: standardize naming/config of shutl_rails/shutl_resource/shutl_auth
- @uri ||= URI Shutl.authentication_service[:url]
+ @uri ||= URI Shutl::Auth.url
end
end
end
View
39 lib/shutl_auth/network_retry_settings.rb
@@ -0,0 +1,39 @@
+module Shutl
+
+ module NetworkRetrySettings
+ extend self
+
+ def retry_connection message= "Notice: Network Exception", default=nil
+ Retriable.retriable(retry_settings) { yield }
+ rescue *network_exceptions => e
+ Airbrake.notify(e, error_message: message)
+ default
+ end
+
+ private
+
+ def network_exceptions
+ [
+ Timeout::Error,
+ Errno::ECONNREFUSED,
+ EOFError,
+ Net::HTTPBadResponse,
+ Errno::ETIMEDOUT
+ ]
+ end
+
+ def retry_settings options = {}
+ interval = options[:sleep] || (test_mode ? 0 : 1)
+ {on: network_exceptions, tries: 3, interval: interval}.merge options
+ end
+
+ #override based on environment
+ def test_mode
+ false
+ end
+ end
+
+ class << self
+ delegate :retry_connection, to: NetworkRetrySettings
+ end
+end
View
1 shutl_auth.gemspec
@@ -17,6 +17,7 @@ Gem::Specification.new do |gem|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ["lib"]
+ gem.add_dependency 'retriable'
gem.add_dependency 'rack-oauth2'
gem.add_development_dependency 'rspec', '~> 2.11.0'
View
5 spec/spec_helper.rb
@@ -1,2 +1,7 @@
require 'webmock/rspec'
require 'shutl_auth'
+module Airbrake
+ def self.notify *args
+
+ end
+end

0 comments on commit d79d1fb

Please sign in to comment.
Something went wrong with that request. Please try again.