Method: Cnvrg::Project#spot_will_terminate

Defined in:
lib/cnvrg/project.rb

#spot_will_terminateObject



747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
# File 'lib/cnvrg/project.rb', line 747

def spot_will_terminate
  restart = false
  config = self.get_config
  # logic that will prevent multiple restart calls
  if config[:spot_taken]
    return false
  end
  begin
    url = URI.parse('http://169.254.169.254/latest/meta-data/spot/termination-time')
    req = Net::HTTP::Get.new(url.to_s)
    res = Net::HTTP.start(url.host, url.port) {|http|
      http.request(req)
    }
    unless res.body.include? "404"
      restart = true
    end
    if res.body.include? "Empty reply from server"
      restart = false
    end
  rescue
    restart = false
  end

  if restart
    config[:spot_taken] = true
    self.set_config(config)
  end

  return restart
end