lib/gooddata/rest/client.rb in gooddata-0.6.16 vs lib/gooddata/rest/client.rb in gooddata-0.6.17
- old
+ new
@@ -18,10 +18,12 @@
class Client
#################################
# Constants
#################################
DEFAULT_CONNECTION_IMPLEMENTATION = GoodData::Rest::Connection
+ DEFAULT_SLEEP_INTERVAL = 10
+ DEFAULT_POLL_TIME_LIMIT = 5 * 60 * 60 # 5 hours
#################################
# Class variables
#################################
@@instance = nil # rubocop:disable ClassVars
@@ -205,10 +207,14 @@
def stats_on? # rubocop:disable Style/TrivialAccessors
@stats
end
+ def generate_request_id
+ @connection.generate_request_id
+ end
+
#######################
# Rest
#######################
# HTTP DELETE
#
@@ -229,12 +235,13 @@
fail ArgumentError, 'No :project specified' if p.nil?
project = GoodData::Project[p, opts]
fail ArgumentError, 'Wrong :project specified' if project.nil?
- u = URI(project.links['uploads'])
- URI.join(u.to_s.chomp(u.path.to_s), '/project-uploads/', "#{project.pid}/")
+ url = project.links['uploads']
+ fail 'Project WebDAV not supported in this Data Center' unless url
+ url
end
def user_webdav_path(opts = { :project => GoodData.project })
p = opts[:project]
fail ArgumentError, 'No :project specified' if p.nil?
@@ -255,21 +262,17 @@
# @param link [String] Link for polling
# @param options [Hash] Options
# @return [Hash] Result of polling
def poll_on_code(link, options = {})
code = options[:code] || 202
- sleep_interval = options[:sleep_interval] || DEFAULT_SLEEP_INTERVAL
- response = get(link, :process => false)
+ process = options[:process]
- while response.code == code
- sleep sleep_interval
- GoodData::Rest::Client.retryable(:tries => 3, :refresh_token => proc { connection.refresh_token }) do
- sleep sleep_interval
- response = get(link, :process => false)
- end
+ response = poll_on_response(link, options.merge(:process => false)) do |resp|
+ resp.code == code
end
- if options[:process] == false
+
+ if process == false
response
else
get(link)
end
end
@@ -283,15 +286,26 @@
# @param link [String] Link for polling
# @param options [Hash] Options
# @return [Hash] Result of polling
def poll_on_response(link, options = {}, &bl)
sleep_interval = options[:sleep_interval] || DEFAULT_SLEEP_INTERVAL
- response = get(link)
+ time_limit = options[:time_limit] || DEFAULT_POLL_TIME_LIMIT
+
+ # by default the response is processed
+ process = options[:process]
+
+ # get the first status and start the timer
+ response = get(link, :process => process)
+ poll_start = Time.now
+
while bl.call(response)
+ if time_limit && (Time.now - poll_start > time_limit)
+ fail "The time limit #{time_limit} secs for polling on #{link} is over"
+ end
sleep sleep_interval
GoodData::Rest::Client.retryable(:tries => 3, :refresh_token => proc { connection.refresh_token }) do
sleep sleep_interval
- response = get(link)
+ response = get(link, :process => process)
end
end
response
end