Skip to content

Commit f0dd25a

Browse files
Merge pull request #2084 from gooddata/GRIF-877
fix(lcm): Add retry with refresh token during upload file
2 parents a237a35 + 3ff0258 commit f0dd25a

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎lib/gooddata/rest/connection.rb‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,22 @@ def create_webdav_dir_if_needed(url)
527527
def do_stream_file(uri, filename, _options = {})
528528
GoodData.logger.info "Uploading file user storage #{uri}"
529529

530-
request = RestClient::Request.new(:method => :put,
531-
:url => uri.to_s,
532-
:verify_ssl => verify_ssl,
533-
:headers => @webdav_headers.merge(:x_gdc_authtt => headers[:x_gdc_authtt]),
534-
:payload => File.new(filename, 'rb'))
530+
# Build the request inside the retryable block so that, after a token
531+
# refresh triggered by a 401, the new x_gdc_authtt header is picked up
532+
# and a fresh file handle is used for the retried upload.
533+
b = proc do
534+
request = RestClient::Request.new(:method => :put,
535+
:url => uri.to_s,
536+
:verify_ssl => verify_ssl,
537+
:headers => @webdav_headers.merge(:x_gdc_authtt => headers[:x_gdc_authtt]),
538+
:payload => File.new(filename, 'rb'))
539+
request.execute
540+
end
535541

536542
begin
537-
request.execute
543+
GoodData::Rest::Connection.retryable(:tries => Helpers::GD_MAX_RETRY, :refresh_token => proc { refresh_token }) do
544+
b.call
545+
end
538546
rescue => e
539547
raise "Error when uploading file #{filename}. Error: #{e}"
540548
end

‎spec/project/full_process_schedule_spec.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
end
229229
end
230230

231-
xit "should be possible to download deployed process" do
231+
it "should be possible to download deployed process" do
232232
process = @project.deploy_process('./spec/data/hello_world_process/hello_world.zip',
233233
type: 'RUBY',
234234
name: 'Test ETL zipped file Process')

0 commit comments

Comments
 (0)