Module: Gitlab::Triage::Retryable

Included in:
RestAPINetwork
Defined in:
lib/gitlab/triage/retryable.rb

Constant Summary collapse

MAX_RETRIES =
3
BACK_OFF_SECONDS =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#triesObject

Returns the value of attribute tries.



7
8
9
# File 'lib/gitlab/triage/retryable.rb', line 7

def tries
  @tries
end

Instance Method Details

#execute_with_retry(exception_types: [StandardError], backoff_exceptions: []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/triage/retryable.rb', line 9

def execute_with_retry(exception_types: [StandardError], backoff_exceptions: [])
  @tries = 0

  until maximum_retries_reached?
    begin
      @tries += 1
      return yield
    rescue *exception_types
      raise if maximum_retries_reached?
    rescue *backoff_exceptions
      raise if maximum_retries_reached?

      sleep(BACK_OFF_SECONDS)
    end
  end
end

#maximum_retries_reached?Boolean (private)

Returns:

  • (Boolean)


28
29
30
# File 'lib/gitlab/triage/retryable.rb', line 28

def maximum_retries_reached?
  tries == MAX_RETRIES
end