Module: TestPoller
- Included in:
- Deltacloud::Image, Deltacloud::Instance, Deltacloud::StorageSnapshot
- Defined in:
- lib/deltacloud/api.rb
Instance Method Summary collapse
-
#wait_for!(driver, opts = {}, &block) ⇒ Object
This method will pool the resource until condition is true Will raise ‘Timeout’ when it reach retry count.
Instance Method Details
#wait_for!(driver, opts = {}, &block) ⇒ Object
This method will pool the resource until condition is true Will raise ‘Timeout’ when it reach retry count
default opts => 10 default opts => 10 (seconds) default opts => 60 (seconds) -> single request timeout
opts => Proc -> executed ‘before’ making each request opts => Proc -> executed ‘after’ making each request
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/deltacloud/api.rb', line 38 def wait_for!(driver, opts={}, &block) opts[:retries] ||= 10 opts[:time_between_retry] ||= 10 opts[:timeout] ||= 60 opts[:method] ||= self.class.name.split('::').last.downcase.to_sym opts[:retries].downto(0) do |r| result = begin timeout(opts[:timeout]) do if opts[:before] new_instance = opts[:before].call(r) { driver.send(opts[:method], :id => self.id) } else new_instance = driver.send(opts[:method], :id => self.id) end ((yield new_instance) == true) ? new_instance : false end rescue Timeout::Error false ensure opts[:after].call(r) if opts[:after] end return result unless result == false sleep(opts[:time_between_retry]) end raise Timeout::Error end |