Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Dec 12, 2024
1 parent 8e9e9d5 commit a255ce6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion async-container-demo/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GEM
console (~> 1.29)
fiber-annotation
io-event (~> 1.6, >= 1.6.5)
console (1.29.0)
console (1.29.2)
fiber-annotation
fiber-local (~> 1.1)
json
Expand Down
4 changes: 2 additions & 2 deletions async-container-demo/start
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Console.logger.debug!
class WebController < Async::Container::Controller
def setup(container)
container.spawn(name: "Web") do |instance|
instance.exec("bundle", "exec", "web")
instance.exec("bundle", "exec", "web", ready: false)
end

# container.spawn(name: "Jobs") do |instance|
Expand All @@ -46,7 +46,7 @@ pgid = Process.getpgid(pid)
Thread.new do
sleep 5
Console.debug(self, "Sending HUP signal to restart container...")
Process.kill("HUP", -pgid)
Process.kill("HUP", pid)

# sleep 5
# Console.debug(self, "Sending INT signal to stop container...")
Expand Down
6 changes: 6 additions & 0 deletions async-container-demo/web
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "console"
require "async/container/notify"

Console.logger.debug!

Expand All @@ -13,6 +14,11 @@ class Web
def start
Console.debug(self, "Starting web...")

if notify = Async::Container::Notify.open!
Console.info(self, "Notifying container ready...")
notify.ready!
end

loop do
Console.info(self, "Web running...")

Expand Down
20 changes: 12 additions & 8 deletions lib/async/container/process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,28 @@ def terminate!
end

# Wait for the child process to exit.
# @asynchronous This method may block.
#
# @returns [::Process::Status] The process exit status.
def wait
$stderr.puts "Waiting for #{@pid}...", caller

if @pid && @status.nil?
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
Console.debug(self, "Waiting for process to exit...", pid: @pid)

if @status.nil?
sleep(0.01)
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
end

if @status.nil?
_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)

while @status.nil?
Console.warn(self) {"Process #{@pid} is blocking, has it exited?"}
_, @status = ::Process.wait2(@pid)

sleep(0.1)

_, @status = ::Process.wait2(@pid, ::Process::WNOHANG)
end
end

Console.debug(self, "Process exited.", pid: @pid, status: @status)

return @status
end
end
Expand Down

0 comments on commit a255ce6

Please sign in to comment.