Sha256: 8e4fc55f7ee0c7be5de36f851820dd394ce65bd4f99e85a0978f6bafefb5b7d0
Contents?: true
Size: 1.75 KB
Versions: 17
Compression:
Stored size: 1.75 KB
Contents
require 'time' module KumoDockerCloud class StateValidator attr_reader :state_provider def initialize(state_provider) @state_provider = state_provider @stateful = nil end def wait_for_state(expected_state, time_limit) start_time = Time.now last_state = nil while Time.now.to_i - start_time.to_i < time_limit @stateful = state_provider.call if last_state != current_state print "\n#{@stateful[:name]} is currently #{current_state}" else print "." end last_state = current_state if current_state == expected_state break end sleep(1) end print "\n" if current_state != expected_state puts "Timed out after #{time_limit} seconds" raise TimeoutError.new end end def wait_for_exit_state(time_limit) start_time = Time.now while Time.now.to_i - start_time.to_i < time_limit @stateful = state_provider.call print "." unless current_exit_code.nil? break end sleep(1) end print "\n" if current_exit_code.nil? puts "#{@stateful[:name]} deployment timed out after #{time_limit} seconds" raise TimeoutError.new end if current_exit_code != 0 error_message = "#{@stateful[:name]} deployment failed with exit code #{current_exit_code}" puts error_message raise error_message end end private def current_state return 'an unknown state' if @stateful.nil? @stateful.fetch(:state, 'an unknown state') end def current_exit_code return 'an unknown state' if @stateful.nil? @stateful.fetch(:exit_code, nil) end end end
Version data entries
17 entries across 17 versions & 1 rubygems