async-container 0.17.1 → 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: ca8c53ca974eedc0759ad1d030e4ccedc9aa223911a37954c1a60736ca97ec66
4
- data.tar.gz: c1ea63c60f1b3d8890a9bff9bdf2ba07347bec4fb4c589da0cc6517382fa8ae5
3
+ metadata.gz: 9dc9673efdab7c4237e091e9efe316438d6a514b625dfbc4b9fc68d245a90d87
4
+ data.tar.gz: 7d48600b8d3396997101c828bea5878a3124f1449e7bbdb5467ce8fd044c6eba
5
5
  SHA512:
6
- metadata.gz: 0f5f2433accfc4f8e4f702a420df060eee14594ec03d260ce4f048349650edcd541ee7256010003a71b9164bd2ac152941c069dde5847e7e0db387b5da02a5fe
7
- data.tar.gz: f352c280c2c6a5de77657e32cba0d256daa09bf0e14254a96b2e95983ed598ebdaa1f5e3e9e4d8c0029616caa29d8e83dd3e47b3382cb16a8a91e07d8081db9a
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)
@@ -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.1"
8
+ VERSION = "0.18.0"
9
9
  end
10
10
  end
data.tar.gz.sig CHANGED
@@ -1,2 +1,5 @@
1
- <r����p�X5[H3��O���H8B�ܸ96��%bj��f8�*1���cë\?,sh{ق�&�sd�@���/�$_\'�
2
- ��3<��/�����qa^-�XhHeRRr��,��A7k�2��"Ya�[
1
+ EMrRd+^�d���D�0�6X��D9��Ԗ/t�$B(�@��*;�'��kL]U�=Wx���C1����Z��\����=�6�,��^j�N�
2
+ إ��� Ue<n��ԝ� U+�g ��dftq��H
3
+ �H�?f
4
+ �`��Of��3l�>��ӠW�M����lAZޣ�r}3�
5
+ �D��W�C�Q ��ܕ�'�G#�[tӣ�v^�� (hq�}T�gv�XrW
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.1
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-22 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