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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/async/container/supervisor.rb +7 -1
- data/lib/async/container/supervisor/client.rb +6 -2
- data/lib/async/container/supervisor/connection.rb +19 -5
- data/lib/async/container/supervisor/version.rb +1 -1
- data/lib/async/container/supervisor/worker.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +2 -4
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9013912b7ef22165d93ebf5f6958d26be67b99f601a28b3ac6e7208fc4e8db54
|
|
4
|
+
data.tar.gz: 2de566c74dc9fabad2bc5ccb0f0bf329581860fbb8e27f14944cefecfacef9b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
247
|
-
@stream.
|
|
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
|
-
#
|
|
296
|
+
# Enqueue the response for the call:
|
|
283
297
|
call.push(**message)
|
|
284
298
|
elsif message.key?(:do)
|
|
285
|
-
#
|
|
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
|
-
#
|
|
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
|
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
data.tar.gz.sig
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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)MAM]�66���O�OAK�by�h;j�d�%d�V�[hs[4�tt}�Zo`A)�.
|
metadata
CHANGED
metadata.gz.sig
CHANGED
|
Binary file
|