4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/maestro_common/utils/retryable.rb', line 4
def Utils.retryable(options = {}, &block)
options[:on] = [options[:on]] unless options[:on].nil? or options[:on].is_a?(Array)
opts = { :tries => 1, :on => [StandardError], :sleep => 20 }.merge(options)
retry_exception, retries, snooze = opts[:on], opts[:tries], opts[:sleep]
count = 0
begin
count += 1
return yield
rescue *retry_exception => e
Maestro.log.warn "Attempt ##{count}: Failed with #{e.class} #{e}, retrying in #{opts[:sleep]} seconds."
sleep snooze
retry if count < retries
end
yield
end
|