retries = 0 begin 1 / 0 if retries < 2 puts "ok" rescue => exception raise if retries >= 2 sleep(0.5 * 1.5**retries) retries += 1 puts "#{retries}回目のリトライ" retry end # >> 1回目のリトライ # >> 2回目のリトライ # >> ok require "retriable" Retriable.configure do |c| c.base_interval = 0.5 c.multiplier = 1.5 c.on_retry = -> exception, try, elapsed_time, interval { puts "#{try}回目のリトライ" } end Retriable.retriable do |i|