Skip to content

Commit bda392b

Browse files
committed
Extra logging, especially some failure paths.
1 parent a2c6b82 commit bda392b

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

lib/async/container/controller.rb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ def setup(container)
9191
# Start the container unless it's already running.
9292
def start
9393
unless @container
94-
Console.info(self) {"Controller starting..."}
94+
Console.info(self, "Controller starting...")
9595
self.restart
9696
end
9797

98-
Console.info(self) {"Controller started..."}
98+
Console.info(self, "Controller started...")
9999
end
100100

101101
# Stop the container if it's running.
@@ -111,9 +111,9 @@ def restart
111111
if @container
112112
@notify&.restarting!
113113

114-
Console.debug(self) {"Restarting container..."}
114+
Console.info(self, "Restarting container...")
115115
else
116-
Console.debug(self) {"Starting container..."}
116+
Console.info(self, "Starting container...")
117117
end
118118

119119
container = self.create_container
@@ -127,13 +127,14 @@ def restart
127127
end
128128

129129
# Wait for all child processes to enter the ready state.
130-
Console.debug(self, "Waiting for startup...")
130+
Console.info(self, "Waiting for startup...")
131131
container.wait_until_ready
132-
Console.debug(self, "Finished startup.")
132+
Console.info(self, "Finished startup.")
133133

134134
if container.failed?
135135
@notify&.error!("Container failed to start!")
136136

137+
Console.info(self, "Stopping failed container...")
137138
container.stop(false)
138139

139140
raise SetupError, container
@@ -145,7 +146,7 @@ def restart
145146
container = nil
146147

147148
if old_container
148-
Console.debug(self, "Stopping old container...")
149+
Console.info(self, "Stopping old container...")
149150
old_container&.stop(@graceful_stop)
150151
end
151152

@@ -168,11 +169,9 @@ def reload
168169
end
169170

170171
# Wait for all child processes to enter the ready state.
171-
Console.debug(self, "Waiting for startup...")
172-
172+
Console.info(self, "Waiting for startup...")
173173
@container.wait_until_ready
174-
175-
Console.debug(self, "Finished startup.")
174+
Console.info(self, "Finished startup.")
176175

177176
if @container.failed?
178177
@notify.error!("Container failed to reload!")

lib/async/container/generic.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,18 @@ def wait_until_ready
139139
# Stop the children instances.
140140
# @parameter timeout [Boolean | Numeric] Whether to stop gracefully, or a specific timeout.
141141
def stop(timeout = true)
142+
Console.info(self, "Stopping container...", timeout: timeout, caller: caller_locations)
142143
@running = false
143144
@group.stop(timeout)
144145

145146
if @group.running?
146-
Console.warn(self) {"Group is still running after stopping it!"}
147+
Console.warn(self, "Group is still running after stopping it!")
148+
else
149+
Console.info(self, "Group has stopped.")
147150
end
151+
rescue => error
152+
Console.error(self, "Error while stopping container!", exception: error)
153+
raise
148154
ensure
149155
@running = true
150156
end
@@ -165,7 +171,7 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
165171
name ||= UNNAMED
166172

167173
if mark?(key)
168-
Console.debug(self) {"Reusing existing child for #{key}: #{name}"}
174+
Console.debug(self, "Reusing existing child.", child: {key: key, name: name})
169175
return false
170176
end
171177

@@ -199,10 +205,10 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
199205
end
200206

201207
if status.success?
202-
Console.debug(self) {"#{child} exited with #{status}"}
208+
Console.info(self, "Child exited successfully.", status: status, running: @running)
203209
else
204210
@statistics.failure!
205-
Console.error(self, status: status)
211+
Console.error(self, "Child exited with error!", status: status, running: @running)
206212
end
207213

208214
if restart
@@ -211,6 +217,11 @@ def spawn(name: nil, restart: false, key: nil, health_check_timeout: nil, &block
211217
break
212218
end
213219
end
220+
rescue => error
221+
Console.error(self, "Failure during child process management!", exception: error, running: @running)
222+
raise
223+
ensure
224+
Console.info(self, "Child process management loop exited.", running: @running)
214225
end.resume
215226

216227
return true

releases.md

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

3+
## Unreleased
4+
5+
- More logging, especially around failure cases.
6+
37
## v0.27.1
48

59
- Log caller and timeout when waiting on a child instance to exit, if it blocks.

0 commit comments

Comments
 (0)