Class: Integer

Inherits:
Object show all
Defined in:
lib/kaki/utils/retry.rb

Instance Method Summary collapse

Instance Method Details

#times_retry(message: true, wait: 0) ⇒ Object

例外ならばブロックを n 回リトライする


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kaki/utils/retry.rb', line 3

def times_retry(message: true, wait: 0)
  n = 1
  begin
    yield(n)
  rescue => e
    if n <= self
      puts "Error: retry #{n}" if message
      puts e.backtrace if message
      n += 1
      sleep(wait)
      retry
    end
    puts "Error: stop" if message
    raise e
  end
end