Skip to content

Commit a255ce6

Browse files
committed
WIP.
1 parent 8e9e9d5 commit a255ce6

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

async-container-demo/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GEM
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

async-container-demo/start

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Console.logger.debug!
2020
class 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)
4646
Thread.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...")

async-container-demo/web

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require "console"
5+
require "async/container/notify"
56

67
Console.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

lib/async/container/process.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)