File tree Expand file tree Collapse file tree 4 files changed +21
-11
lines changed
Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Original file line number Diff line number Diff line change 1111 console (~> 1.29 )
1212 fiber-annotation
1313 io-event (~> 1.6 , >= 1.6.5 )
14- console (1.29.0 )
14+ console (1.29.2 )
1515 fiber-annotation
1616 fiber-local (~> 1.1 )
1717 json
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Console.logger.debug!
2020class WebController < Async ::Container ::Controller
2121 def setup ( container )
2222 container . spawn ( name : "Web" ) do |instance |
23- instance . exec ( "bundle" , "exec" , "web" )
23+ instance . exec ( "bundle" , "exec" , "web" , ready : false )
2424 end
2525
2626 # container.spawn(name: "Jobs") do |instance|
@@ -46,7 +46,7 @@ pgid = Process.getpgid(pid)
4646Thread . new do
4747 sleep 5
4848 Console . debug ( self , "Sending HUP signal to restart container..." )
49- Process . kill ( "HUP" , - pgid )
49+ Process . kill ( "HUP" , pid )
5050
5151 # sleep 5
5252 # Console.debug(self, "Sending INT signal to stop container...")
Original file line number Diff line number Diff line change 22# frozen_string_literal: true
33
44require "console"
5+ require "async/container/notify"
56
67Console . logger . debug!
78
@@ -13,6 +14,11 @@ class Web
1314 def start
1415 Console . debug ( self , "Starting web..." )
1516
17+ if notify = Async ::Container ::Notify . open!
18+ Console . info ( self , "Notifying container ready..." )
19+ notify . ready!
20+ end
21+
1622 loop do
1723 Console . info ( self , "Web running..." )
1824
Original file line number Diff line number Diff line change @@ -151,24 +151,28 @@ def terminate!
151151 end
152152
153153 # Wait for the child process to exit.
154+ # @asynchronous This method may block.
155+ #
154156 # @returns [::Process::Status] The process exit status.
155157 def wait
156158 $stderr. puts "Waiting for #{ @pid } ..." , caller
157159
158160 if @pid && @status . nil?
159- _ , @status = :: Process . wait2 ( @pid , :: Process :: WNOHANG )
161+ Console . debug ( self , "Waiting for process to exit..." , pid : @pid )
160162
161- if @status . nil?
162- sleep ( 0.01 )
163- _ , @status = ::Process . wait2 ( @pid , ::Process ::WNOHANG )
164- end
165-
166- if @status . nil?
163+ _ , @status = ::Process . wait2 ( @pid , ::Process ::WNOHANG )
164+
165+ while @status . nil?
167166 Console . warn ( self ) { "Process #{ @pid } is blocking, has it exited?" }
168- _ , @status = ::Process . wait2 ( @pid )
167+
168+ sleep ( 0.1 )
169+
170+ _ , @status = ::Process . wait2 ( @pid , ::Process ::WNOHANG )
169171 end
170172 end
171173
174+ Console . debug ( self , "Process exited." , pid : @pid , status : @status )
175+
172176 return @status
173177 end
174178 end
You can’t perform that action at this time.
0 commit comments