Sha256: 80a321b1865daa04b17f2613eb79d4c58b10ec988add02aab1240289b252d627
Contents?: true
Size: 721 Bytes
Versions: 3
Compression:
Stored size: 721 Bytes
Contents
module MailFetcher module RetryHelper def eventually(options = {}) options = {:tries => 10, :delay => 1, :catch => []}.merge(options) last_error = nil start_time = Time.now.to_i options[:tries].times do |i| begin result = yield i return result if result rescue => e raise e unless Array(options[:catch]).any? { |type| e.is_a?(type) } last_error = e end timeout = options[:timeout] || (options[:tries] * options[:delay]) if (Time.now.to_i - start_time) > timeout break else sleep(options[:delay]) end end raise last_error if last_error nil end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
mail_fetcher-0.0.4 | lib/mail_fetcher/retry_helper.rb |
mail_fetcher-0.0.3 | lib/mail_fetcher/retry_helper.rb |
mail_fetcher-0.0.2 | lib/mail_fetcher/retry_helper.rb |