Module: GithubAuthentication::Retriable

Included in:
Http, Provider
Defined in:
lib/github_authentication/retriable.rb

Instance Method Summary collapse

Instance Method Details

#with_retries(*exceptions, max_attempts: 4, sleep_between_attempts: 0.1, exponential_backoff: true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/github_authentication/retriable.rb', line 5

def with_retries(*exceptions, max_attempts: 4, sleep_between_attempts: 0.1, exponential_backoff: true)
  attempt = 1
  previous_failure = nil

  begin
    return_value = yield(attempt, previous_failure)
  rescue *exceptions => exception
    raise if attempt >= max_attempts

    sleep_after_attempt(
      attempt: attempt,
      base_sleep_time: sleep_between_attempts,
      exponential_backoff: exponential_backoff,
    )

    attempt += 1
    previous_failure = exception
    retry
  else
    return_value
  end
end