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
base_message = "exception - %s, waiting #{RETRY_WAIT_SECONDS} secs)"
if maximum_retries_reached?
puts_execute_with_retry_message(e, format(base_message, "gave up, tried #{MAX_RETRIES} times")) if debug
raise
else
puts_execute_with_retry_message(e, format(base_message, "retrying #{@tries}/#{MAX_RETRIES} times")) if debug
sleep(RETRY_WAIT_SECONDS)
end
rescue *backoff_exceptions => e
base_message = "backoff - %s, waiting #{BACK_OFF_SECONDS} secs)"
if maximum_retries_reached?
puts_execute_with_retry_message(e, format(base_message, "gave up, tried #{MAX_RETRIES} times")) if debug
raise
else
puts_execute_with_retry_message(e, format(base_message, "retrying #{@tries}/#{MAX_RETRIES} times")) if debug
sleep(BACK_OFF_SECONDS)
end
end
end
end
|