Module: Gitlab::Triage::Retryable
- Included in:
- RestAPINetwork
- Defined in:
- lib/gitlab/triage/retryable.rb
Constant Summary collapse
- MAX_RETRIES =
3- RETRY_WAIT_SECONDS =
10- BACK_OFF_SECONDS =
10
Instance Attribute Summary collapse
-
#tries ⇒ Object
Returns the value of attribute tries.
Instance Method Summary collapse
- #execute_with_retry(exception_types: [StandardError], backoff_exceptions: [], debug: false) ⇒ Object
- #maximum_retries_reached? ⇒ Boolean private
- #puts_execute_with_retry_message(exception, message) ⇒ Object private
Instance Attribute Details
#tries ⇒ Object
Returns the value of attribute tries.
10 11 12 |
# File 'lib/gitlab/triage/retryable.rb', line 10 def tries @tries end |
Instance Method Details
#execute_with_retry(exception_types: [StandardError], backoff_exceptions: [], debug: false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/gitlab/triage/retryable.rb', line 12 def execute_with_retry(exception_types: [StandardError], backoff_exceptions: [], debug: false) @tries = 0 until maximum_retries_reached? begin @tries += 1 return yield rescue *exception_types => e = "exception - %s, waiting #{RETRY_WAIT_SECONDS} secs)" if maximum_retries_reached? (e, format(, "gave up, tried #{MAX_RETRIES} times")) if debug raise else (e, format(, "retrying #{@tries}/#{MAX_RETRIES} times")) if debug sleep(RETRY_WAIT_SECONDS) end rescue *backoff_exceptions => e = "backoff - %s, waiting #{BACK_OFF_SECONDS} secs)" if maximum_retries_reached? (e, format(, "gave up, tried #{MAX_RETRIES} times")) if debug raise else (e, format(, "retrying #{@tries}/#{MAX_RETRIES} times")) if debug sleep(BACK_OFF_SECONDS) end end end end |
#maximum_retries_reached? ⇒ Boolean (private)
45 46 47 |
# File 'lib/gitlab/triage/retryable.rb', line 45 def maximum_retries_reached? tries == MAX_RETRIES end |
#puts_execute_with_retry_message(exception, message) ⇒ Object (private)
49 50 51 |
# File 'lib/gitlab/triage/retryable.rb', line 49 def (exception, ) puts Gitlab::Triage::UI.debug "execute_with_retry: #{exception} (#{message}" end |