Skip to content

Commit

Permalink
Implement Helpers::GD_MAX_RETRY
Browse files Browse the repository at this point in the history
  • Loading branch information
korczis committed Dec 1, 2016
1 parent d8afd81 commit 697df15
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# GoodData Ruby SDK Changelog

## 0.6.49
- Implement Helpers::GD_MAX_RETRY to allow max retries override

## 0.6.48
- Fix jruby issue with uninitialized constant GoodData::Rest::Connection::ConnectionHelper

Expand Down
3 changes: 3 additions & 0 deletions lib/gooddata/helpers/global_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'hashie'
require 'openssl'

require_relative '../extensions/object'
require_relative 'global_helpers_params'

module GoodData
Expand All @@ -17,6 +18,8 @@ class DeepMergeableHash < Hash
include Hashie::Extensions::DeepMerge
end

set_const :GD_MAX_RETRY, (ENV['GD_MAX_RETRY'] && ENV['GD_MAX_RETRY'].to_i) || 3

class << self
def error(msg)
STDERR.puts(msg)
Expand Down
3 changes: 2 additions & 1 deletion lib/gooddata/rest/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'rest-client'

require_relative '../helpers/auth_helpers'
require_relative '../helpers/global_helpers'

require_relative 'connection'
require_relative 'object_factory'
Expand Down Expand Up @@ -329,7 +330,7 @@ def poll_on_response(link, options = {}, &bl)
fail ExecutionLimitExceeded, "The time limit #{time_limit} secs for polling on #{link} is over"
end
sleep sleep_interval
GoodData::Rest::Client.retryable(:tries => ConnectionHelper::GD_MAX_RETRY, :refresh_token => proc { connection.refresh_token }) do
GoodData::Rest::Client.retryable(:tries => Helpers::GD_MAX_RETRY, :refresh_token => proc { connection.refresh_token }) do
response = get(link, process: process)
end
end
Expand Down
10 changes: 6 additions & 4 deletions lib/gooddata/rest/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
require_relative '../version'
require_relative '../exceptions/exceptions'

require_relative '../helpers/global_helpers'

module RestClient
module AbstractResponse
alias_method :old_follow_redirection, :follow_redirection
Expand Down Expand Up @@ -288,7 +290,7 @@ def download(what, where, options = {})
end
end

GoodData::Rest::Connection.retryable(:tries => ConnectionHelper::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
GoodData::Rest::Connection.retryable(:tries => Helpers::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
if where.is_a?(IO) || where.is_a?(StringIO)
b.call(where)
else
Expand Down Expand Up @@ -486,7 +488,7 @@ def create_webdav_dir_if_needed(url)
RestClient::Request.execute(raw)
end

GoodData::Rest::Connection.retryable(:tries => ConnectionHelper::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
GoodData::Rest::Connection.retryable(:tries => Helpers::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
b.call
end
end
Expand Down Expand Up @@ -543,7 +545,7 @@ def merge_headers!(headers)
end

def process_response(options = {}, &block)
retries = options[:tries] || 3 # ConnectionHelper::GD_MAX_RETRY
retries = options[:tries] || Helpers::GD_MAX_RETRY
process = options[:process]
dont_reauth = options[:dont_reauth]
options = options.reject { |k, _| [:process, :dont_reauth].include?(k) }
Expand Down Expand Up @@ -700,7 +702,7 @@ def webdav_dir_exists?(url)
method = :get
GoodData.logger.debug "#{method}: #{url}"

GoodData::Rest::Connection.retryable(:tries => ConnectionHelper::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
GoodData::Rest::Connection.retryable(:tries => Helpers::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
raw = {
:method => method,
:url => url,
Expand Down
2 changes: 1 addition & 1 deletion lib/gooddata/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# GoodData Module
module GoodData
VERSION = '0.6.48'
VERSION = '0.6.49'

class << self
# Version
Expand Down
2 changes: 1 addition & 1 deletion spec/environment/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module GoodData
module Environment
module ConnectionHelper
set_const :GD_PROJECT_TOKEN, ENV["GD_PROJECT_TOKEN"]
set_const :GD_MAX_RETRY, (ENV["GD_MAX_RETRY"] && ENV["GD_MAX_RETRY"].to_i) || 3
set_const :GD_MAX_RETRY, Helpers::GD_MAX_RETRY

set_const :DEFAULT_USERNAME, "[email protected]"
set_const :TEST_USERNAME, "[email protected]"
Expand Down

0 comments on commit 697df15

Please sign in to comment.