Skip to content
代码片段 群组 项目
提交 27353c24 编辑于 作者: George Koltsov's avatar George Koltsov 提交者: Halil Coban
浏览文件

Retry exceptions during BulkImports::FileDownloadService

Changelog: other
上级 54fd7de3
No related branches found
No related tags found
无相关合并请求
...@@ -58,6 +58,13 @@ def download_file ...@@ -58,6 +58,13 @@ def download_file
http_client.stream(relative_url) do |chunk| http_client.stream(relative_url) do |chunk|
next if bytes_downloaded == 0 && [301, 302, 303, 307, 308].include?(chunk.code) next if bytes_downloaded == 0 && [301, 302, 303, 307, 308].include?(chunk.code)
if BulkImports::NetworkError::RETRIABLE_HTTP_CODES.include?(chunk.code)
raise BulkImports::NetworkError.new(
"Error downloading file from #{relative_url}. Error code: #{chunk.code}",
response: chunk.http_response
)
end
@response_code = chunk.code @response_code = chunk.code
@response_headers ||= Gitlab::HTTP::Response::Headers.new(chunk.http_response.to_hash) @response_headers ||= Gitlab::HTTP::Response::Headers.new(chunk.http_response.to_hash)
@last_chunk_context = chunk.to_s.truncate(LAST_CHUNK_CONTEXT_CHAR_LIMIT) @last_chunk_context = chunk.to_s.truncate(LAST_CHUNK_CONTEXT_CHAR_LIMIT)
......
...@@ -18,7 +18,7 @@ class NetworkError < Error ...@@ -18,7 +18,7 @@ class NetworkError < Error
Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ENETUNREACH
].freeze ].freeze
RETRIABLE_HTTP_CODES = [429].freeze RETRIABLE_HTTP_CODES = [429, 500, 502, 503, 504].freeze
DEFAULT_RETRY_DELAY_SECONDS = 30 DEFAULT_RETRY_DELAY_SECONDS = 30
...@@ -57,7 +57,7 @@ def retriable_exception? ...@@ -57,7 +57,7 @@ def retriable_exception?
end end
def retriable_http_code? def retriable_http_code?
RETRIABLE_HTTP_CODES.include?(response&.code) RETRIABLE_HTTP_CODES.include?(response&.code.to_i)
end end
def increment(object) def increment(object)
......
...@@ -322,7 +322,7 @@ def load(context, data); end ...@@ -322,7 +322,7 @@ def load(context, data); end
end end
context 'when exception is not retriable' do context 'when exception is not retriable' do
let(:reponse_status_code) { 503 } let(:reponse_status_code) { 505 }
it_behaves_like 'failed pipeline', 'BulkImports::NetworkError', 'Net::ReadTimeout' it_behaves_like 'failed pipeline', 'BulkImports::NetworkError', 'Net::ReadTimeout'
end end
......
...@@ -149,15 +149,26 @@ ...@@ -149,15 +149,26 @@
end end
context 'when chunk code is not 200' do context 'when chunk code is not 200' do
let(:chunk_code) { 500 } let(:chunk_code) { 404 }
it 'raises an error' do it 'raises an error' do
expect { subject.execute }.to raise_error( expect { subject.execute }.to raise_error(
described_class::ServiceError, described_class::ServiceError,
'File download error 500' 'File download error 404'
) )
end end
context 'when chunk code is retriable' do
let(:chunk_code) { 502 }
it 'raises a retriable error' do
expect { subject.execute }.to raise_error(
BulkImports::NetworkError,
'Error downloading file from /test. Error code: 502'
)
end
end
context 'when chunk code is redirection' do context 'when chunk code is redirection' do
let(:chunk_code) { 303 } let(:chunk_code) { 303 }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册