Exception: BulkImports::NetworkError

Inherits:
Error
  • Object
show all
Defined in:
lib/bulk_imports/network_error.rb

Constant Summary collapse

COUNTER_KEY =
'bulk_imports/%{entity_id}/%{stage}/%{tracker_id}/network_error/%{error}'
RETRIABLE_EXCEPTIONS =
Gitlab::HTTP::HTTP_TIMEOUT_ERRORS
RETRIABLE_HTTP_CODES =
[429].freeze
DEFAULT_RETRY_DELAY_SECONDS =
60
MAX_RETRIABLE_COUNT =
3

Instance Method Summary collapse

Methods inherited from Error

unsupported_gitlab_version

Constructor Details

#initialize(message = nil, response: nil) ⇒ NetworkError

Returns a new instance of NetworkError.

Raises:

  • (ArgumentError)

14
15
16
17
18
19
20
# File 'lib/bulk_imports/network_error.rb', line 14

def initialize(message = nil, response: nil)
  raise ArgumentError, 'message or response required' if message.blank? && response.blank?

  super(message)

  @response = response
end

Instance Method Details

#retriable?(tracker) ⇒ Boolean

Returns:

  • (Boolean)

22
23
24
25
26
27
28
# File 'lib/bulk_imports/network_error.rb', line 22

def retriable?(tracker)
  if retriable_exception? || retriable_http_code?
    increment(tracker) <= MAX_RETRIABLE_COUNT
  else
    false
  end
end

#retry_delayObject


30
31
32
33
34
35
36
# File 'lib/bulk_imports/network_error.rb', line 30

def retry_delay
  if response&.code == 429
    response.headers.fetch('Retry-After', DEFAULT_RETRY_DELAY_SECONDS).to_i
  else
    DEFAULT_RETRY_DELAY_SECONDS
  end.seconds
end