async-container-supervisor 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b9684c9b4ef621c8b92411d251478b9751cc901e251fa1b35c3fca92af18763
4
- data.tar.gz: 5e9f9a25b01f4de9c160aa194acd2a3467215d09ccbbdfbac178c2bb1f278e58
3
+ metadata.gz: 9013912b7ef22165d93ebf5f6958d26be67b99f601a28b3ac6e7208fc4e8db54
4
+ data.tar.gz: 2de566c74dc9fabad2bc5ccb0f0bf329581860fbb8e27f14944cefecfacef9b2
5
5
  SHA512:
6
- metadata.gz: 7fa18caa63bb5dff847b3640c63ca5c2109a3003537bf36cf8ac2947d560a8c0dc5d201b79e98c789e991db415fb2b07aa2c8a9cf94f556f2d932d68d4044dd4
7
- data.tar.gz: 235f540925cc1ea12f1f2ef89df5cfacca213e56c4a0b39514f610a92e93e7de995e087842eb827936daa954802631ced0f5ca89ae22f7441c69763f10d7bc6b
6
+ metadata.gz: bde00386e4f3faa439e149b872bb22075725f05235769a1b5084760f059e0e1aed7a669dec9232125aa5053b1afdf09a016c444a16918c4da92210169e9e50b0
7
+ data.tar.gz: 844be24d31216db2cdfb978aaf888d15be0982e3211c384e7239bd564ef08880d5d870d887084319232ce6760594b37974623c11c5686c433c92ae3de960e67d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -44,7 +44,13 @@ def memory_sample(duration: 10, connection_id:)
44
44
  operation = {do: :memory_sample, duration: duration}
45
45
 
46
46
  # Use the forward operation to proxy the request to a worker:
47
- return connection.call(do: :forward, operation: operation, connection_id: connection_id)
47
+ response = connection.call(do: :forward, operation: operation, connection_id: connection_id)
48
+
49
+ if response && response.key?(:data)
50
+ JSON.parse(response[:data], symbolize_names: true)
51
+ else
52
+ response
53
+ end
48
54
  end
49
55
  end
50
56
 
@@ -48,11 +48,11 @@ module Async
48
48
 
49
49
  # Run the client in a loop, reconnecting if necessary.
50
50
  def run
51
- Async(annotation: "Supervisor Client", transient: true) do
51
+ Async(annotation: "Supervisor Client", transient: true) do |task|
52
52
  loop do
53
53
  connection = connect!
54
54
 
55
- Async do
55
+ connected_task = task.async do
56
56
  connected!(connection)
57
57
  end
58
58
 
@@ -61,6 +61,10 @@ module Async
61
61
  Console.error(self, "Connection failed:", exception: error)
62
62
  sleep(rand)
63
63
  ensure
64
+ # Ensure any tasks that were created during connection are stopped:
65
+ connected_task&.stop
66
+
67
+ # Close the connection itself:
64
68
  connection&.close
65
69
  end
66
70
  end
@@ -147,10 +147,13 @@ module Async
147
147
  def self.dispatch(connection, target, id, message)
148
148
  Async do
149
149
  call = self.new(connection, id, message)
150
+ # Track the call in the connection's calls hash:
150
151
  connection.calls[id] = call
151
152
 
153
+ # Dispatch the call to the target (synchronously):
152
154
  target.dispatch(call)
153
155
 
156
+ # Stream responses back to the connection (asynchronously):
154
157
  while response = call.pop
155
158
  connection.write(id: id, **response)
156
159
  end
@@ -160,6 +163,9 @@ module Async
160
163
 
161
164
  # If the queue is closed, we don't need to send a finished message:
162
165
  unless call.closed?
166
+ # Ensure the call is closed, to prevent messages being buffered:
167
+ call.close
168
+
163
169
  # If the above write failed, this is likely to fail too, and we can safely ignore it.
164
170
  connection.write(id: id, finished: true) rescue nil
165
171
  end
@@ -207,7 +213,11 @@ module Async
207
213
  end
208
214
  end
209
215
  ensure
216
+ # Ensure the call is removed from the connection's calls hash, otherwise it will leak:
210
217
  connection.calls.delete(id)
218
+
219
+ # Ensure the call is closed, so that `Call#pop` will return `nil`.
220
+ call.close
211
221
  end
212
222
  end
213
223
  end
@@ -243,8 +253,9 @@ module Async
243
253
  #
244
254
  # @parameter message [Hash] The message to write.
245
255
  def write(**message)
246
- @stream.write(JSON.dump(message) << "\n")
247
- @stream.flush
256
+ raise IOError, "Connection is closed!" unless @stream
257
+ @stream&.write(JSON.dump(message) << "\n")
258
+ @stream&.flush # it is possible for @stream to become nil after the write call
248
259
  end
249
260
 
250
261
  # Read a message from the connection stream.
@@ -276,16 +287,19 @@ module Async
276
287
  #
277
288
  # @parameter target [Dispatchable] The target to dispatch calls to.
278
289
  def run(target)
290
+ # Process incoming messages from the connection:
279
291
  self.each do |message|
292
+ # If the message has an ID, it is a response to a call:
280
293
  if id = message.delete(:id)
294
+ # Find the call in the connection's calls hash:
281
295
  if call = @calls[id]
282
- # Response to a call:
296
+ # Enqueue the response for the call:
283
297
  call.push(**message)
284
298
  elsif message.key?(:do)
285
- # Incoming call:
299
+ # Otherwise, if we couldn't find an existing call, it must be a new call:
286
300
  Call.dispatch(self, target, id, message)
287
301
  else
288
- # Likely a response to a timed-out call, ignore it:
302
+ # Finally, if none of the above, it is likely a response to a timed-out call, so ignore it:
289
303
  Console.debug(self, "Ignoring message:", message)
290
304
  end
291
305
  else
@@ -9,7 +9,7 @@ module Async
9
9
  module Container
10
10
  # @namespace
11
11
  module Supervisor
12
- VERSION = "0.9.0"
12
+ VERSION = "0.9.2"
13
13
  end
14
14
  end
15
15
  end
@@ -117,7 +117,7 @@ module Async
117
117
  report = sampler.report
118
118
 
119
119
  dump(call) do |file|
120
- file.puts(report.to_s)
120
+ file.puts(report.to_json)
121
121
  end
122
122
  ensure
123
123
  GC.start
data/readme.md CHANGED
@@ -26,6 +26,10 @@ Please see the [project documentation](https://socketry.github.io/async-containe
26
26
 
27
27
  Please see the [project releases](https://socketry.github.io/async-container-supervisor/releases/index) for all releases.
28
28
 
29
+ ### v0.9.1
30
+
31
+ - Close `Call` queue if asynchronous call fails during dispatch - further messages will fail with `ClosedQueueError`.
32
+
29
33
  ### v0.9.0
30
34
 
31
35
  - Better handling of write failures in `Connection::Call.dispatch`, ensuring we don't leak calls.
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.9.1
4
+
5
+ - Close `Call` queue if asynchronous call fails during dispatch - further messages will fail with `ClosedQueueError`.
6
+
3
7
  ## v0.9.0
4
8
 
5
9
  - Better handling of write failures in `Connection::Call.dispatch`, ensuring we don't leak calls.
data.tar.gz.sig CHANGED
@@ -1,4 +1,2 @@
1
- �9��b�l=�<���(Cܝy�뼍���fIl���Q�km1������� .���jW>�����k����q% I:�;%��� Ot�*�ϻ�wW3Im��Z�!�_�� ��<u��~������}[��y�ۤG( �a'��+k�H:˒���%�)�l��J����ؠS
2
- H��-�*C��R6g&�Kk��mL�7���(
3
- '�U\� v�=B�;��Iv~b�6�~x��Wˋ&�����b�ke��y*6����D�0>�ת@k�22dR4bL����QZ�p,�TƸ ��U&�.���2v�X�02���?1��ヌ_Dv:D��X̄S�h�
4
- ����|ܺ�H�R��:�[-��"x��v}^7�lgo
1
+ )X��&!�$l@v���8�� a�u6<QF!��[�` �Xm��6�&,'�F���W�, $��i�|��S6
2
+ ����2�4��!RT�.S��%,eP�@����G{�r7g�T˖����e���nc�#_�N�[\�Y#�- ��I0��l��5�����B�NdO;9��_�����/�$����oF!M>�=F^L �ľ$7��V��w�'e�T�B�����*bl�Z��^��:Td���-7N������+,7i�4[M��.]���O|���2slA��u�����yK�3�O���U � �������sG+�$Bf��=j)M AM]�66���O�OAK�by�h;j�d�%d�V�[hs[4�tt}�Zo`A)�.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-container-supervisor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file