You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Serializes lifecycle transitions such as start, restart and reload. `Container#stop` (which can also take time) is performed outside this guard, so that live container events are not blocked by the stop operation (e.g. restarting).
# Wait for all child processes to enter the ready state.
262
+
Console.info(self,"Waiting for startup...")
263
+
@container.wait_until_ready
264
+
Console.info(self,"Finished startup.")
265
+
266
+
if@container.failed?
267
+
@notify.error!("Container failed to reload!")
268
+
269
+
raiseSetupError,@container
270
+
else
271
+
@notify&.ready!(size: @container.size,status: "Running with #{@container.size} children.")
272
+
end
258
273
end
259
-
260
-
# Wait for all child processes to enter the ready state.
261
-
Console.info(self,"Waiting for startup...")
262
-
@container.wait_until_ready
263
-
Console.info(self,"Finished startup.")
264
-
265
-
if@container.failed?
266
-
@notify.error!("Container failed to reload!")
274
+
end
275
+
276
+
privatedefwait_for_container
277
+
whiletrue
278
+
container=@guard.synchronize{@container}
267
279
268
-
raiseSetupError,@container
269
-
else
270
-
@notify&.ready!(size: @container.size,status: "Running with #{@container.size} children.")
280
+
ifcontainer.nil?
281
+
@events.close
282
+
return
283
+
end
284
+
285
+
container.wait
286
+
287
+
@guard.synchronizedo
288
+
# If this is still the active container, it completed naturally. Clear it and close the event queue so the controller run loop can finish. If it was replaced by a restart, keep waiting for the new active container.
289
+
if@container.equal?(container)
290
+
@container=nil
291
+
@events.close
292
+
return
293
+
end
294
+
end
271
295
end
272
296
end
273
297
274
298
# Enter the controller run loop.
275
-
defrun
299
+
# @parameter signals [#install] The signal backend to use while running the controller.
300
+
defrun(signals: Async::Signals.default)
276
301
@notify&.status!("Initializing controller...")
277
302
278
-
Async::Signals.install(@signals)do
279
-
self.start
280
-
281
-
whileevent=@events.pop(timeout: 0)
282
-
returnifevent.call == :stop
283
-
end
284
-
285
-
while@container&.running?
286
-
@container.wait(@events)
303
+
signals.install(@signals)do
304
+
Syncdo |task|
305
+
self.start
306
+
307
+
waiter=task.async{wait_for_container}
287
308
288
-
whileevent=@events.pop(timeout: 0)
289
-
returnifevent.call == :stop
309
+
whileevent=@events.pop
310
+
event.call
290
311
end
312
+
rescueAsync::Cancel
313
+
# Graceful shutdown:
314
+
self.stop
315
+
ensure
316
+
# Forced shutdown:
317
+
self.stop(false)
291
318
end
292
319
end
293
-
ensure
294
-
self.stop(false)
320
+
rescueInterrupt
321
+
# Ignore - normal shutdown - can propagate from top level Sync.
0 commit comments