class KumoDockerCloud::StateValidator
Attributes
state_provider[R]
Public Class Methods
new(state_provider)
click to toggle source
# File lib/kumo_dockercloud/state_validator.rb, line 7 def initialize(state_provider) @state_provider = state_provider @stateful = nil end
Public Instance Methods
wait_for_exit_state(time_limit)
click to toggle source
# File lib/kumo_dockercloud/state_validator.rb, line 40 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
wait_for_state(expected_state, time_limit)
click to toggle source
# File lib/kumo_dockercloud/state_validator.rb, line 12 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
Private Instance Methods
current_exit_code()
click to toggle source
# File lib/kumo_dockercloud/state_validator.rb, line 76 def current_exit_code return 'an unknown state' if @stateful.nil? @stateful.fetch(:exit_code, nil) end
current_state()
click to toggle source
# File lib/kumo_dockercloud/state_validator.rb, line 71 def current_state return 'an unknown state' if @stateful.nil? @stateful.fetch(:state, 'an unknown state') end