Class: KumoDockerCloud::StateValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/kumo_dockercloud/state_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state_provider) ⇒ StateValidator

Returns a new instance of StateValidator.



7
8
9
10
# File 'lib/kumo_dockercloud/state_validator.rb', line 7

def initialize(state_provider)
  @state_provider = state_provider
  @stateful = nil
end

Instance Attribute Details

#state_providerObject (readonly)

Returns the value of attribute state_provider.



5
6
7
# File 'lib/kumo_dockercloud/state_validator.rb', line 5

def state_provider
  @state_provider
end

Instance Method Details

#wait_for_exit_state(time_limit) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# 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) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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