class OpenShift::Runtime::Utils::Hourglass

This class provides a very simple countdown object which can be used to drive time-boxed operations.

Upon initialization, the current time is noted, and calls to remaining will be relative to the start time and supplied duration (expressed in seconds).

Attributes

end_time[R]

Public Class Methods

new(duration) click to toggle source
# File lib/openshift-origin-node/utils/hourglass.rb, line 17
def initialize(duration)
  @duration = duration
  @start_time = Time.now
  @end_time = @start_time + @duration
end

Public Instance Methods

elapsed() click to toggle source

Returns the number of seconds elapsed since the start time.

# File lib/openshift-origin-node/utils/hourglass.rb, line 26
def elapsed
  (Time.now - @start_time).round
end
expired?() click to toggle source

Returns true if the duration has been exceeded, otherwise false.

# File lib/openshift-origin-node/utils/hourglass.rb, line 41
def expired?
  remaining.zero?
end
remaining() click to toggle source

Returns the number of seconds remaining until expiration, or zero if the hourglass has expired.

# File lib/openshift-origin-node/utils/hourglass.rb, line 34
def remaining
  [0, @duration - elapsed].max
end