Class: Travis::Lock::Retry
- Inherits:
-
Struct
- Object
- Struct
- Travis::Lock::Retry
- Defined in:
- lib/travis/lock/support/retry.rb
Constant Summary collapse
- WAIT =
0.0001..0.0009
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #run ⇒ Object
- #started ⇒ Object
- #timeout ⇒ Object
- #timeout! ⇒ Object
- #timeout? ⇒ Boolean
- #wait ⇒ Object
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/travis/lock/support/retry.rb', line 3 def name @name end |
#options ⇒ Object
Returns the value of attribute options
3 4 5 |
# File 'lib/travis/lock/support/retry.rb', line 3 def @options end |
Instance Method Details
#run ⇒ Object
6 7 8 9 |
# File 'lib/travis/lock/support/retry.rb', line 6 def run wait until result = yield result end |
#started ⇒ Object
16 17 18 |
# File 'lib/travis/lock/support/retry.rb', line 16 def started @started ||= Time.now end |
#timeout ⇒ Object
24 25 26 |
# File 'lib/travis/lock/support/retry.rb', line 24 def timeout [:timeout] || 30 end |
#timeout! ⇒ Object
28 29 30 |
# File 'lib/travis/lock/support/retry.rb', line 28 def timeout! fail Timeout.new(name, ) end |
#timeout? ⇒ Boolean
20 21 22 |
# File 'lib/travis/lock/support/retry.rb', line 20 def timeout? started + timeout < Time.now end |
#wait ⇒ Object
11 12 13 14 |
# File 'lib/travis/lock/support/retry.rb', line 11 def wait sleep(rand([:wait] || WAIT)) timeout! if timeout? end |