Module: Patriot::Util::Retry
- Included in:
- JobStore::InMemoryStore, JobStore::RDBJobStore, Worker::Base
- Defined in:
- lib/patriot/util/retry.rb
Overview
a mudule enables operations to be retried
Class Method Summary collapse
-
.execute_with_retry(retry_config = {}, &blk) ⇒ Object
execute block and retry the block.
Class Method Details
.execute_with_retry(retry_config = {}, &blk) ⇒ Object
execute block and retry the block
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/patriot/util/retry.rb', line 10 def execute_with_retry(retry_config = {}, &blk) retry_config = {:num_retry => 3, :wait_time => 3}.merge(retry_config) e = nil 1.upto(retry_config[:num_retry]) do |i| begin return yield rescue Exception => e if @logger @logger.error "fail to execute (#{i}) #{blk.to_s}" @logger.error e $@.each{|m| @logger.error m} end end sleep retry_config[:wait_time] end raise e unless e.nil? end |