artery 1.4.2 → 1.4.3
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/lib/artery/active_record/message.rb +4 -1
- data/lib/artery/active_record/model_info.rb +4 -0
- data/lib/artery/model/subscriptions.rb +16 -1
- data/lib/artery/subscription/synchronization.rb +46 -0
- data/lib/artery/subscription.rb +13 -0
- data/lib/artery/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6fc6ee867a6031d7ad94fa40630261f079c23664833cb79a40d7100445967d27
|
|
4
|
+
data.tar.gz: 38bc318bbc6d76c4ac86138c0fa60e2f61001cc9e869a36f2931243bac208780
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09d04bc9c56091cb5f9092c882b9127e5362092ccee797cba608dc3dd59131277a283dc85a852bd5e1ff5bdebb6276c5f1c415417cfc1eb3679d854c8754b8d7'
|
|
7
|
+
data.tar.gz: dcd7b59c4288f0669aff6141b21e46aaaef2e7e5467b41d98d1d108a5f83729d6aea1bbe96c9e2d6c1cec501cd318cd59bd09c00c979234dfb8f598133118695
|
|
@@ -20,7 +20,10 @@ module Artery
|
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def latest_index(model)
|
|
23
|
-
where(model: model).maximum(:id).to_i
|
|
23
|
+
last_message_id = where(model: model).maximum(:id).to_i
|
|
24
|
+
return last_message_id unless last_message_id.zero?
|
|
25
|
+
|
|
26
|
+
Artery.model_info_class.last_published_id_for(model)
|
|
24
27
|
end
|
|
25
28
|
|
|
26
29
|
def delete_old
|
|
@@ -48,7 +48,22 @@ module Artery
|
|
|
48
48
|
model ||= artery_model_name
|
|
49
49
|
action ||= '*'
|
|
50
50
|
|
|
51
|
-
artery_add_subscription Routing.uri(service: service, model: model, action: action), kwargs,
|
|
51
|
+
artery_add_subscription Routing.uri(service: service, model: model, action: action), **kwargs, client: true,
|
|
52
|
+
&blk
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def artery_rewind_message_counter!(service: nil) # rubocop:disable Naming/PredicateMethod
|
|
56
|
+
return false if artery_source_model?
|
|
57
|
+
|
|
58
|
+
subscriptions = artery[:subscriptions]&.select do |subscription|
|
|
59
|
+
next false unless subscription.rewindable?
|
|
60
|
+
|
|
61
|
+
service.nil? || subscription.uri.service.to_sym == service.to_sym
|
|
62
|
+
end
|
|
63
|
+
return false if subscriptions.blank?
|
|
64
|
+
|
|
65
|
+
subscriptions.each(&:rewind_message_counter!)
|
|
66
|
+
true
|
|
52
67
|
end
|
|
53
68
|
|
|
54
69
|
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
@@ -97,8 +97,54 @@ module Artery
|
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
+
def rewind_message_counter! # rubocop:disable Naming/PredicateMethod
|
|
101
|
+
return false unless rewindable?
|
|
102
|
+
|
|
103
|
+
local_index = latest_message_index
|
|
104
|
+
return false unless local_index.positive?
|
|
105
|
+
|
|
106
|
+
remote_index = request_publisher_latest_index!
|
|
107
|
+
return false unless remote_index.positive?
|
|
108
|
+
return false if remote_index >= local_index
|
|
109
|
+
|
|
110
|
+
Artery.logger.info(
|
|
111
|
+
"Rewinding #{uri} latest_index from #{local_index} to #{remote_index}"
|
|
112
|
+
)
|
|
113
|
+
info.update!(latest_index: remote_index)
|
|
114
|
+
true
|
|
115
|
+
end
|
|
116
|
+
|
|
100
117
|
private
|
|
101
118
|
|
|
119
|
+
def request_publisher_latest_index!
|
|
120
|
+
route = Routing.uri(
|
|
121
|
+
service: uri.service,
|
|
122
|
+
model: uri.model,
|
|
123
|
+
plural: true,
|
|
124
|
+
action: :get_all
|
|
125
|
+
).to_route
|
|
126
|
+
|
|
127
|
+
remote_index = nil
|
|
128
|
+
|
|
129
|
+
Artery.request(
|
|
130
|
+
route,
|
|
131
|
+
representation: representation_name,
|
|
132
|
+
scope: synchronize_updates_scope,
|
|
133
|
+
page: 0,
|
|
134
|
+
per_page: 1
|
|
135
|
+
) do |on|
|
|
136
|
+
on.success do |data|
|
|
137
|
+
remote_index = data[:_index].to_i
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
on.error do |error|
|
|
141
|
+
raise Error, "Failed to fetch artery index for #{uri}: #{error.message}"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
remote_index.to_i
|
|
146
|
+
end
|
|
147
|
+
|
|
102
148
|
def run_synchronization_heartbeat
|
|
103
149
|
return if @heartbeat_thread
|
|
104
150
|
|
data/lib/artery/subscription.rb
CHANGED
|
@@ -28,6 +28,11 @@ module Artery
|
|
|
28
28
|
@info ||= Artery.subscription_info_class.find_for_subscription(self)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def reset_info!
|
|
32
|
+
@info = nil
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
|
|
31
36
|
def representation_name
|
|
32
37
|
options[:representation]
|
|
33
38
|
end
|
|
@@ -40,6 +45,14 @@ module Artery
|
|
|
40
45
|
@subscriber.artery[:source]
|
|
41
46
|
end
|
|
42
47
|
|
|
48
|
+
def client?
|
|
49
|
+
options[:client]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def rewindable?
|
|
53
|
+
client? && synchronize_updates?
|
|
54
|
+
end
|
|
55
|
+
|
|
43
56
|
def latest_outgoing_message_index
|
|
44
57
|
return unless source?
|
|
45
58
|
|
data/lib/artery/version.rb
CHANGED