Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/services/gpo_confirmation_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ def generate_export(confirmations)
def upload_export(export)
return unless FeatureManagement.gpo_upload_enabled?
io = StringIO.new(export)
Net::SFTP.start(*sftp_config) do |sftp|
sftp.upload!(io, remote_path)

with_retries(
max_tries: 5,
rescue: [Net::SFTP::Exception, Net::SSH::Exception],
) do
Net::SFTP.start(*sftp_config) do |sftp|
sftp.upload!(io, remote_path)
end
end
end

Expand Down
22 changes: 22 additions & 0 deletions spec/services/gpo_confirmation_uploader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,28 @@

subject
end

context 'when an SSH error occurs' do
it 'retries the upload' do
expect(Net::SFTP).to receive(:start).twice.with(*sftp_options).and_yield(sftp_connection)
expect(sftp_connection).to receive(:upload!).once.and_raise(Net::SSH::ConnectionTimeout)
expect(sftp_connection).to receive(:upload!).once

subject
end

it 'raises after 5 unsuccessful retries' do
expect(Net::SFTP).to receive(:start).
exactly(5).times.
with(*sftp_options).
and_yield(sftp_connection)
expect(sftp_connection).to receive(:upload!).
exactly(5).times.
and_raise(Net::SSH::ConnectionTimeout)

expect { subject }.to raise_error(Net::SSH::ConnectionTimeout)
end
end
end

describe '#run' do
Expand Down