@@ -45,19 +45,34 @@ namespace :orchestrator do
4545 abort ( "#{ args [ :container ] } is not healthy" ) unless Sagittarius ::Orchestrator ::State [ args [ :container ] ] . healthy?
4646 end
4747
48- auto_reenable_task :await_healthy , %i[ container timeout ] => :build_state do |_ , args |
48+ auto_reenable_task :await_healthy , %i[ container timeout min_attempts ] => :build_state do |_ , args |
4949 timeout = args . fetch ( :timeout , 30 ) . to_i
50+ min_attempts = args . fetch ( :min_attempts , 2 ) . to_i
5051 container = Sagittarius ::Orchestrator ::State [ args [ :container ] ]
5152
52- ( 0 ..timeout ) . each do |attempt |
53+ total_attempts = 0
54+ successful_attempts = 0
55+ ( 0 ..timeout ) . each do
56+ total_attempts += 1
5357 if container . healthy?
54- puts "#{ container . name } is healthy after #{ attempt } seconds"
55- break
58+ successful_attempts += 1
59+ else
60+ successful_attempts = 0
5661 end
62+
63+ break if successful_attempts >= min_attempts
64+
5765 sleep 1
5866 end
5967
60- abort ( "#{ container . name } did not get healthy within #{ timeout } seconds" ) unless container . healthy?
68+ if successful_attempts >= min_attempts
69+ puts "#{ container . name } is healthy after #{ total_attempts } seconds"
70+ elsif container . healthy?
71+ abort ( "#{ container . name } did get healthy, but did not meet health threshold of " \
72+ "#{ min_attempts } within #{ timeout } seconds" )
73+ else
74+ abort ( "#{ container . name } did not get healthy within #{ timeout } seconds" )
75+ end
6176 end
6277
6378 task :create_connection_environment , [ ] => :build_state do |_ , args |
0 commit comments