artery 1.4.4 → 1.4.5
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
- data/README.md +6 -0
- data/lib/artery/backend.rb +1 -0
- data/lib/artery/pending_reply.rb +21 -0
- data/lib/artery/version.rb +1 -1
- data/lib/artery/worker.rb +26 -13
- data/lib/artery.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7581793e30cd47b17305eba1471eefe0253706d1314eaca0182330cc767eccea
|
|
4
|
+
data.tar.gz: cd70c83548faade1ad7647a9e14a51f7ee9b3793cb183cf3f404bc041e5c74b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8336606139dd4ffee2df5f145ab7c1d173a31454fe616728333614a670e28485ea5860c5d1afbd23fb533f9d06c86cab3d67b5fdee5b4de351c5817a65ad2672
|
|
7
|
+
data.tar.gz: ba8bb91901b2f306099a0c27408d2b451318b61dfb0e065ae44b78681327fe737f4ba8a334fc989306f47774d1926e6aef2a8b9a637c228699eb4f52d654c5ad
|
data/README.md
CHANGED
|
@@ -27,6 +27,12 @@ $ rake artery:install:migrations
|
|
|
27
27
|
$ rake db:migrate
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
## Request errors
|
|
31
|
+
|
|
32
|
+
If a subscription raises an unhandled exception, the worker reports it and runs the remaining subscriptions for that delivery. If no handler published to the request's reply inbox through `Artery.publish` during synchronous dispatch, the worker replies with `{"error":"internal_error"}`. The requester receives an `Artery::RequestError` through `on.error`.
|
|
33
|
+
|
|
34
|
+
An explicit success or error reply takes precedence over this fallback. If all handlers finish normally without replying, the requester still waits for its timeout. Replies from other processes or asynchronous jobs are outside the worker's tracking scope.
|
|
35
|
+
|
|
30
36
|
## Publishing modes
|
|
31
37
|
|
|
32
38
|
Artery supports two modes for publishing messages to NATS:
|
data/lib/artery/backend.rb
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Artery
|
|
4
|
+
module PendingReply
|
|
5
|
+
module_function
|
|
6
|
+
|
|
7
|
+
# A synchronous nested delivery must restore the enclosing delivery's inbox.
|
|
8
|
+
def unanswered?(reply)
|
|
9
|
+
previous = Thread.current[:artery_pending_reply]
|
|
10
|
+
Thread.current[:artery_pending_reply] = reply.presence
|
|
11
|
+
yield
|
|
12
|
+
Thread.current[:artery_pending_reply].present?
|
|
13
|
+
ensure
|
|
14
|
+
Thread.current[:artery_pending_reply] = previous
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def published(route)
|
|
18
|
+
Thread.current[:artery_pending_reply] = nil if Thread.current[:artery_pending_reply] == route
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/artery/version.rb
CHANGED
data/lib/artery/worker.rb
CHANGED
|
@@ -48,19 +48,7 @@ module Artery
|
|
|
48
48
|
subscriptions_on_services.each do |uri, subscriptions|
|
|
49
49
|
Artery::Instrumentation.instrument(:worker, action: :subscribing, route: uri.to_s)
|
|
50
50
|
Artery.subscribe uri.to_route, queue: "#{Artery.service_name}.worker" do |data, reply, from|
|
|
51
|
-
subscriptions
|
|
52
|
-
message = Subscription::IncomingMessage.new subscription, data, reply, from
|
|
53
|
-
|
|
54
|
-
subscription.handle(message)
|
|
55
|
-
rescue StandardError => e
|
|
56
|
-
Artery.handle_error Error.new("Error in subscription handling: #{e.inspect}",
|
|
57
|
-
original_exception: e,
|
|
58
|
-
subscription: {
|
|
59
|
-
subscriber: subscription.subscriber.to_s,
|
|
60
|
-
route: from,
|
|
61
|
-
data: data.to_json
|
|
62
|
-
})
|
|
63
|
-
end
|
|
51
|
+
dispatch(subscriptions, data, reply, from)
|
|
64
52
|
end
|
|
65
53
|
end
|
|
66
54
|
rescue StandardError => e
|
|
@@ -73,5 +61,30 @@ module Artery
|
|
|
73
61
|
end
|
|
74
62
|
end
|
|
75
63
|
end
|
|
64
|
+
|
|
65
|
+
def dispatch(subscriptions, data, reply, from)
|
|
66
|
+
failed = false
|
|
67
|
+
unanswered = PendingReply.unanswered?(reply) do
|
|
68
|
+
subscriptions.each do |subscription|
|
|
69
|
+
message = Subscription::IncomingMessage.new(subscription, data, reply, from)
|
|
70
|
+
subscription.handle(message)
|
|
71
|
+
rescue StandardError => e
|
|
72
|
+
failed = true
|
|
73
|
+
Artery.handle_error Error.new("Error in subscription handling: #{e.inspect}",
|
|
74
|
+
original_exception: e,
|
|
75
|
+
subscription: {
|
|
76
|
+
subscriber: subscription.subscriber.to_s, route: from, data: data.to_json
|
|
77
|
+
})
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
publish_error_reply(reply, from) if failed && unanswered
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def publish_error_reply(reply, from)
|
|
84
|
+
Artery.publish(reply, error: 'internal_error')
|
|
85
|
+
rescue StandardError => e
|
|
86
|
+
Artery.handle_error Error.new("Error publishing subscription error reply: #{e.inspect}",
|
|
87
|
+
original_exception: e, subscription: { route: from })
|
|
88
|
+
end
|
|
76
89
|
end
|
|
77
90
|
end
|
data/lib/artery.rb
CHANGED
|
@@ -13,6 +13,7 @@ require_relative 'multiblock_has_block'
|
|
|
13
13
|
module Artery
|
|
14
14
|
autoload :Config, 'artery/config'
|
|
15
15
|
autoload :Publisher, 'artery/publisher'
|
|
16
|
+
autoload :PendingReply, 'artery/pending_reply'
|
|
16
17
|
autoload :Worker, 'artery/worker'
|
|
17
18
|
autoload :Sync, 'artery/sync'
|
|
18
19
|
autoload :Check, 'artery/check'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: artery
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.4.
|
|
4
|
+
version: 1.4.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergey Gnuskov
|
|
@@ -144,6 +144,7 @@ files:
|
|
|
144
144
|
- lib/artery/no_brainer.rb
|
|
145
145
|
- lib/artery/no_brainer/message.rb
|
|
146
146
|
- lib/artery/no_brainer/subscription_info.rb
|
|
147
|
+
- lib/artery/pending_reply.rb
|
|
147
148
|
- lib/artery/publisher.rb
|
|
148
149
|
- lib/artery/routing.rb
|
|
149
150
|
- lib/artery/subscription.rb
|