26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/elastic_beans/command/restart.rb', line 26
def run(environment_type = nil)
environments = []
if environment_type
environment = ElasticBeans::Environment.new_by_type(
environment_type,
queue: queue,
application: application,
elastic_beanstalk: elastic_beanstalk,
)
environments << environment
if environment.status != "Ready"
raise EnvironmentsNotReady.new(environments: environments)
end
else
environments = application.environments
if environments.empty?
raise NoEnvironmentsError
end
unready_environments = environments.select { |environment| environment.status != "Ready" }
if unready_environments.any?
raise EnvironmentsNotReady.new(environments: unready_environments)
end
end
progressbar = ProgressBar.create(title: "Restarting", total: nil, output: ui.stdout)
Signal.trap("INT") do
puts "\nInterrupting beans"
puts "Restart still in progress, follow it in the AWS console"
raise Interrupt
end
Signal.trap("TERM") do
puts "Terminating beans"
puts "Restart still in progress, follow it in the AWS console"
raise SignalException.new("TERM")
end
threads = environments.map { |environment|
progressbar.log("Restarting `#{environment.name}'...")
thread = Thread.new do
environment.restart
end
progressbar.increment
thread
}
loop do
sleep 0.5
progressbar.increment
if threads.none?(&:alive?)
progressbar.total = progressbar.progress
break
end
end
threads.each(&:join)
end
|