Skip to content

Commit 80e9efe

Browse files
committed
Add size (running children) to controller ready! notification.
1 parent 3dccefd commit 80e9efe

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

lib/async/container/controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def restart
149149
old_container&.stop(@graceful_stop)
150150
end
151151

152-
@notify&.ready!
152+
@notify&.ready!(size: @container.size)
153153
ensure
154154
# If we are leaving this function with an exception, try to kill the container:
155155
container&.stop(false)
@@ -185,7 +185,7 @@ def reload
185185

186186
# Enter the controller run loop, trapping `SIGINT` and `SIGTERM`.
187187
def run
188-
@notify&.status!("Initializing...")
188+
@notify&.status!("Initializing controller...")
189189

190190
with_signal_handlers do
191191
self.start

lib/async/container/generic.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def initialize(**options)
5151
# @attribute [Group] The group of running children instances.
5252
attr :group
5353

54+
# @returns [Integer] The number of running children instances.
55+
def size
56+
@group.size
57+
end
58+
5459
# @attribute [Hash(Child, Hash)] The state of each child instance.
5560
attr :state
5661

lib/async/container/group.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ def inspect
3232
# @attribute [Hash(IO, Fiber)] the running tasks, indexed by IO.
3333
attr :running
3434

35+
# @returns [Integer] The number of running processes.
36+
def size
37+
@running.size
38+
end
39+
3540
# Whether the group contains any running processes.
3641
# @returns [Boolean]
3742
def running?

test/async/container/notify/log.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
lines = File.readlines(notify_log).map{|line| JSON.parse(line)}
2020

21-
expect(lines.last).to be == {"ready" => true}
21+
expect(lines.last).to have_keys(
22+
"ready" => be == true,
23+
"size" => be > 0,
24+
)
2225
end
2326
end

test/async/container/notify/pipe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
container.sleep
2525

2626
_child, state = container.state.first
27-
expect(state).to be == {status: "Initializing..."}
27+
expect(state).to be == {status: "Initializing controller..."}
2828

2929
container.wait
3030

0 commit comments

Comments
 (0)