Class: Travis::Lock::Retry

Inherits:
Struct
  • Object
show all
Defined in:
lib/travis/lock/support/retry.rb

Constant Summary collapse

WAIT =
0.0001..0.0009

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/travis/lock/support/retry.rb', line 3

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



3
4
5
# File 'lib/travis/lock/support/retry.rb', line 3

def options
  @options
end

Instance Method Details

#runObject



6
7
8
9
# File 'lib/travis/lock/support/retry.rb', line 6

def run
  wait until result = yield
  result
end

#startedObject



16
17
18
# File 'lib/travis/lock/support/retry.rb', line 16

def started
  @started ||= Time.now
end

#timeoutObject



24
25
26
# File 'lib/travis/lock/support/retry.rb', line 24

def timeout
  options[:timeout] || 30
end

#timeout!Object



28
29
30
# File 'lib/travis/lock/support/retry.rb', line 28

def timeout!
  fail Timeout.new(name, options)
end

#timeout?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/travis/lock/support/retry.rb', line 20

def timeout?
  started + timeout < Time.now
end

#waitObject



11
12
13
14
# File 'lib/travis/lock/support/retry.rb', line 11

def wait
  sleep(rand(options[:wait] || WAIT))
  timeout! if timeout?
end