async-container 0.17.0 → 0.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f6471fbc90b1e7f77f1309460f4c7e4430b1145e7bed34fd2d3bf0328a07e2c
4
- data.tar.gz: 2c31a4e9efa968ecb8990ea75635bfc3ae1f7dfbe4206b6924083ff70e41ac22
3
+ metadata.gz: 9dc9673efdab7c4237e091e9efe316438d6a514b625dfbc4b9fc68d245a90d87
4
+ data.tar.gz: 7d48600b8d3396997101c828bea5878a3124f1449e7bbdb5467ce8fd044c6eba
5
5
  SHA512:
6
- metadata.gz: e238bdbbd25338102c6e50f94ab061d54ffbe297518ed2700f8e351bb96267e651042bf7a3284c518e6954e7dca5d09c3f1ca4ef043051b4fd128c71c1fe8a42
7
- data.tar.gz: c3db488f41fab5ccea99a4cc8e89fc6e79cc687b77284f65991712beb51cc8d434e248d419d94fec5aaf04c63c91bfba037243d53c5ba6aa762645244053f04e
6
+ metadata.gz: 0ea4840c799c1a0dbb0c68a22ea498865a34f041e7ed69596abfc0c40634d190f00202c414bac39a4154072e1300982684522da5cf5a0210a7aaedb1174b767f
7
+ data.tar.gz: dab62559214494aff8c4413bef634bcb0f829e0066710b2069bed339357fab44da97569eb291d32d057763072fff059064c492bea2fc35afec4d51f230def7d5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -22,7 +22,7 @@ module Async
22
22
 
23
23
  # Initialize the controller.
24
24
  # @parameter notify [Notify::Client] A client used for process readiness notifications.
25
- def initialize(notify: Notify.open!, container_class: Container)
25
+ def initialize(notify: Notify.open!, container_class: Container, graceful_stop: true)
26
26
  @container = nil
27
27
  @container_class = container_class
28
28
 
@@ -35,6 +35,8 @@ module Async
35
35
  trap(SIGHUP) do
36
36
  self.restart
37
37
  end
38
+
39
+ @graceful_stop = graceful_stop
38
40
  end
39
41
 
40
42
  # The state of the controller.
@@ -96,7 +98,7 @@ module Async
96
98
 
97
99
  # Stop the container if it's running.
98
100
  # @parameter graceful [Boolean] Whether to give the children instances time to shut down or to kill them immediately.
99
- def stop(graceful = true)
101
+ def stop(graceful = @graceful_stop)
100
102
  @container&.stop(graceful)
101
103
  @container = nil
102
104
  end
@@ -130,23 +132,25 @@ module Async
130
132
  if container.failed?
131
133
  @notify&.error!("Container failed to start!")
132
134
 
133
- container.stop
135
+ container.stop(false)
134
136
 
135
137
  raise SetupError, container
136
138
  end
137
139
 
138
- # Make this swap as atomic as possible:
140
+ # The following swap should be atomic:
139
141
  old_container = @container
140
142
  @container = container
143
+ container = nil
144
+
145
+ if old_container
146
+ Console.logger.debug(self, "Stopping old container...")
147
+ old_container&.stop(@graceful_stop)
148
+ end
141
149
 
142
- Console.logger.debug(self, "Stopping old container...")
143
- old_container&.stop
144
150
  @notify&.ready!
145
- rescue
151
+ ensure
146
152
  # If we are leaving this function with an exception, try to kill the container:
147
153
  container&.stop(false)
148
-
149
- raise
150
154
  end
151
155
 
152
156
  # Reload the existing container. Children instances will be reloaded using `SIGHUP`.
@@ -163,7 +167,9 @@ module Async
163
167
 
164
168
  # Wait for all child processes to enter the ready state.
165
169
  Console.logger.debug(self, "Waiting for startup...")
170
+
166
171
  @container.wait_until_ready
172
+
167
173
  Console.logger.debug(self, "Finished startup.")
168
174
 
169
175
  if @container.failed?
@@ -180,14 +186,17 @@ module Async
180
186
  # I thought this was the default... but it doesn't always raise an exception unless you do this explicitly.
181
187
  # We use `Thread.current.raise(...)` so that exceptions are filtered through `Thread.handle_interrupt` correctly.
182
188
  interrupt_action = Signal.trap(:INT) do
189
+ # $stderr.puts "Received INT signal, terminating...", caller
183
190
  ::Thread.current.raise(Interrupt)
184
191
  end
185
192
 
186
193
  terminate_action = Signal.trap(:TERM) do
194
+ # $stderr.puts "Received TERM signal, terminating...", caller
187
195
  ::Thread.current.raise(Terminate)
188
196
  end
189
197
 
190
198
  hangup_action = Signal.trap(:HUP) do
199
+ # $stderr.puts "Received HUP signal, restarting...", caller
191
200
  ::Thread.current.raise(Hangup)
192
201
  end
193
202
 
@@ -209,11 +218,11 @@ module Async
209
218
  end
210
219
  end
211
220
  rescue Interrupt
212
- self.stop(true)
221
+ self.stop
213
222
  rescue Terminate
214
223
  self.stop(false)
215
224
  ensure
216
- self.stop(true)
225
+ self.stop(false)
217
226
 
218
227
  # Restore the interrupt handler:
219
228
  Signal.trap(:INT, interrupt_action)
@@ -161,7 +161,7 @@ module Async
161
161
  end
162
162
 
163
163
  if status.success?
164
- Console.logger.info(self) {"#{child} exited with #{status}"}
164
+ Console.logger.debug(self) {"#{child} exited with #{status}"}
165
165
  else
166
166
  @statistics.failure!
167
167
  Console.logger.error(self) {status}
@@ -20,6 +20,10 @@ module Async
20
20
  @queue = nil
21
21
  end
22
22
 
23
+ def inspect
24
+ "#<#{self.class} running=#{@running.size}>"
25
+ end
26
+
23
27
  # @attribute [Hash(IO, Fiber)] the running tasks, indexed by IO.
24
28
  attr :running
25
29
 
@@ -133,6 +137,7 @@ module Async
133
137
  protected
134
138
 
135
139
  def wait_for_children(duration = nil)
140
+ Console.debug(self, "Waiting for children...", duration: duration)
136
141
  if !@running.empty?
137
142
  # Maybe consider using a proper event loop here:
138
143
  readable, _, _ = ::IO.select(@running.keys, nil, nil, duration)
@@ -13,7 +13,7 @@ module Async
13
13
  # Implements a general process readiness protocol with output to the local console.
14
14
  class Console < Client
15
15
  # Open a notification client attached to the current console.
16
- def self.open!(logger = ::Console.logger)
16
+ def self.open!(logger = ::Console)
17
17
  self.new(logger)
18
18
  end
19
19
 
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module Container
8
- VERSION = "0.17.0"
8
+ VERSION = "0.18.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-container
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -41,7 +41,7 @@ cert_chain:
41
41
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
42
42
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
43
43
  -----END CERTIFICATE-----
44
- date: 2024-03-11 00:00:00.000000000 Z
44
+ date: 2024-03-27 00:00:00.000000000 Z
45
45
  dependencies:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: async
metadata.gz.sig CHANGED
Binary file