Module: VSphereCloud::RetryBlock
- Included in:
- AgentEnv, Cloud, DrsLock, FileProvider, VSphereCloud::Resources::VM
- Defined in:
- lib/cloud/vsphere/retry_block.rb
Defined Under Namespace
Classes: TimeoutError
Instance Method Summary collapse
Instance Method Details
#retry_block(num = 2) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/cloud/vsphere/retry_block.rb', line 5 def retry_block(num = 2) result = nil num.times do |i| begin result = yield break rescue raise if i + 1 >= num end end result end |
#retry_with_timeout(timeout) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cloud/vsphere/retry_block.rb', line 18 def retry_with_timeout(timeout) deadline = Time.now.to_i + timeout begin yield rescue if deadline - Time.now.to_i > 0 sleep 0.5 retry end raise TimeoutError end end |