Class: SpotBuild::SpotInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/spot_build/spot_instance.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.scheduled_for_termination?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/spot_build/spot_instance.rb', line 12

def self.scheduled_for_termination?
  !time_until_termination.nil?
end

.time_until_terminationObject



16
17
18
19
20
21
22
23
# File 'lib/spot_build/spot_instance.rb', line 16

def self.time_until_termination
  uri = URI('http://169.254.169.254/latest/meta-data/spot/termination-time')
  response = Net::HTTP.get_response(uri)
  return nil if response.code == "404"
  Time.parse(response.body) - Time.now
rescue ArgumentError
  nil
end

Instance Method Details

#shutdown_if_required(&block) ⇒ Object



6
7
8
9
10
# File 'lib/spot_build/spot_instance.rb', line 6

def shutdown_if_required(&block)
  return false unless self.class.scheduled_for_termination?
  yield
  true
end