Skip to content

Commit 4917723

Browse files
committed
More logging.
1 parent 3768392 commit 4917723

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

lib/async/container/forked.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ def wait(timeout = 0.1)
260260
end
261261
end
262262

263-
264263
# Start a named child process and execute the provided block in it.
265264
# @parameter name [String] The name (title) of the child process.
266265
# @parameter block [Proc] The block to execute in the child process.

lib/async/container/generic.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,13 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
179179

180180
fiber do
181181
while @running
182-
child = self.start(name, &block)
182+
Console.info(self, "Starting child...", child: {key: key, name: name, restart: restart, health_check_timeout: health_check_timeout}, statistics: @statistics)
183183

184+
child = self.start(name, &block)
184185
state = insert(key, child)
185186

187+
Console.info(self, "Started child.", child: child, spawn: {key: key, restart: restart, health_check_timeout: health_check_timeout}, statistics: @statistics)
188+
186189
# If a health check is specified, we will monitor the child process and terminate it if it does not update its state within the specified time.
187190
if health_check_timeout
188191
age_clock = state[:age] = Clock.start

lib/async/container/group.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def stop(graceful = true, interrupt_timeout: INTERRUPT_TIMEOUT, terminate_timeou
183183
self.wait_for_exit(clock, interrupt_timeout)
184184
end
185185

186-
if terminate_timeout
186+
if terminate_timeout and self.any?
187187
clock = Async::Clock.start
188188

189189
# If the children are still running, terminate them:
@@ -231,8 +231,8 @@ def wait_for(channel)
231231
protected
232232

233233
def wait_for_children(duration = nil)
234-
# This log is a big noisy and doesn't really provide a lot of useful information.
235-
# Console.debug(self, "Waiting for children...", duration: duration, running: @running)
234+
# This log is a bit noisy and doesn't really provide a lot of useful information:
235+
Console.debug(self, "Waiting for children...", duration: duration, running: @running)
236236

237237
unless @running.empty?
238238
# Maybe consider using a proper event loop here:

lib/async/container/statistics.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ def << other
5656
@restarts += other.restarts
5757
@failures += other.failures
5858
end
59+
60+
# Generate a hash representation of the statistics.
61+
#
62+
# @returns [Hash] The statistics as a hash.
63+
def as_json(...)
64+
{
65+
spawns: @spawns,
66+
restarts: @restarts,
67+
failures: @failures,
68+
}
69+
end
70+
71+
# Generate a JSON representation of the statistics.
72+
#
73+
# @returns [String] The statistics as JSON.
74+
def to_json(...)
75+
as_json.to_json(...)
76+
end
5977
end
6078
end
6179
end

releases.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Add log for starting child, including container statistics.
6+
- Don't try to (log) "terminate 0 child processes" if there are none.
7+
38
## v0.27.2
49

510
- More logging, especially around failure cases.

0 commit comments

Comments
 (0)