rsmp 0.10.0 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rsmp/collect/alarm_collector.rb +15 -1
- data/lib/rsmp/collect/collector.rb +68 -6
- data/lib/rsmp/collect/state_collector.rb +21 -4
- data/lib/rsmp/logger.rb +2 -3
- data/lib/rsmp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e0f394a4f97656f2ace6156c775c7af4f35ae4023c6bd5c9ad2fd55eca06e3a
|
4
|
+
data.tar.gz: b5e75bf4cb30280fa51e08ee8c42507a7239dc6f7bff57fd0c6f679ca44652b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b8a16e7119b579f81a49d444ae3b2ee0393659eb0dbd84a5f24d4d498b31cf51e0ea355990af5618081c779e41d8c7d33aecb2778f6af2d242de1ee48569050
|
7
|
+
data.tar.gz: 71118e681ee613fecfb5133ec2532813abaa9026d42dd7c58ad5363acbc040cc67d14b899b6a0ab2a6907166967f5125c2d5584ed01d57a3bcaec0a9e1068337
|
data/Gemfile.lock
CHANGED
@@ -9,12 +9,20 @@ module RSMP
|
|
9
9
|
)
|
10
10
|
end
|
11
11
|
|
12
|
+
# match alarm attributes
|
12
13
|
def type_match? message
|
13
14
|
return false if super(message) == false
|
14
15
|
|
15
16
|
# match fixed attributes
|
16
17
|
%w{aCId aSp ack aS sS cat pri}.each do |key|
|
17
|
-
|
18
|
+
want = @query[key]
|
19
|
+
got = message.attribute(key)
|
20
|
+
case want
|
21
|
+
when Regexp
|
22
|
+
return false if got !~ want
|
23
|
+
when String
|
24
|
+
return false if got != want
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
# match rvs items
|
@@ -31,5 +39,11 @@ module RSMP
|
|
31
39
|
end
|
32
40
|
true
|
33
41
|
end
|
42
|
+
|
43
|
+
# return a string that describes what we're collecting
|
44
|
+
def describe_query
|
45
|
+
"#{describe_num_and_type} #{ {component: @options[:component]}.merge(@query).compact }"
|
46
|
+
end
|
47
|
+
|
34
48
|
end
|
35
49
|
end
|
@@ -134,17 +134,18 @@ module RSMP
|
|
134
134
|
# Start collection and return immediately
|
135
135
|
# You can later use wait() to wait for completion
|
136
136
|
def start &block
|
137
|
-
raise RuntimeError.new("Can't
|
137
|
+
raise RuntimeError.new("Can't start collectimng unless ready (currently #{@status})") unless ready?
|
138
138
|
@block = block
|
139
139
|
raise ArgumentError.new("Num, timeout or block must be provided") unless @options[:num] || @options[:timeout] || @block
|
140
140
|
reset
|
141
141
|
@status = :collecting
|
142
|
+
log_start
|
142
143
|
@notifier.add_listener self if @notifier
|
143
144
|
end
|
144
145
|
|
145
146
|
# Build a string describing how how progress reached before timeout
|
146
147
|
def describe_progress
|
147
|
-
str = "#{@title.capitalize} collection "
|
148
|
+
str = "#{identifier}: #{@title.capitalize} collection "
|
148
149
|
str << "in response to #{@options[:m_id]} " if @options[:m_id]
|
149
150
|
str << "didn't complete within #{@options[:timeout]}s, "
|
150
151
|
str << "reached #{@messages.size}/#{@options[:num]}"
|
@@ -167,7 +168,13 @@ module RSMP
|
|
167
168
|
def notify message
|
168
169
|
raise ArgumentError unless message
|
169
170
|
raise RuntimeError.new("can't process message when status is :#{@status}, title: #{@title}, desc: #{describe}") unless ready? || collecting?
|
170
|
-
perform_match message
|
171
|
+
if perform_match message
|
172
|
+
if done?
|
173
|
+
complete
|
174
|
+
else
|
175
|
+
incomplete
|
176
|
+
end
|
177
|
+
end
|
171
178
|
@status
|
172
179
|
end
|
173
180
|
|
@@ -178,6 +185,7 @@ module RSMP
|
|
178
185
|
def perform_match message
|
179
186
|
return false if reject_not_ack(message)
|
180
187
|
return false unless type_match?(message)
|
188
|
+
#@notifier.log "#{identifier}: Looking at #{message.type} #{message.m_id_short}", level: :collect
|
181
189
|
if @block
|
182
190
|
status = [@block.call(message)].flatten
|
183
191
|
return unless collecting?
|
@@ -185,7 +193,6 @@ module RSMP
|
|
185
193
|
else
|
186
194
|
keep message
|
187
195
|
end
|
188
|
-
complete if done?
|
189
196
|
end
|
190
197
|
|
191
198
|
# Have we collected the required number of messages?
|
@@ -198,6 +205,12 @@ module RSMP
|
|
198
205
|
def complete
|
199
206
|
@status = :ok
|
200
207
|
do_stop
|
208
|
+
log_complete
|
209
|
+
end
|
210
|
+
|
211
|
+
# called when we received a message, but are not done yet
|
212
|
+
def incomplete
|
213
|
+
log_incomplete
|
201
214
|
end
|
202
215
|
|
203
216
|
# Remove ourself as a listener, so we don't receive message notifications anymore,
|
@@ -225,14 +238,14 @@ module RSMP
|
|
225
238
|
return unless message
|
226
239
|
klass = message.class.name.split('::').last
|
227
240
|
return unless @options[:type] == nil || [@options[:type]].flatten.include?(klass)
|
228
|
-
@notifier.log "
|
241
|
+
@notifier.log "#{identifier}: cancelled due to schema error in #{klass} #{message.m_id_short}", level: :debug
|
229
242
|
cancel error
|
230
243
|
end
|
231
244
|
|
232
245
|
# Cancel if we received e notificaiton about a disconnect
|
233
246
|
def notify_disconnect error, options
|
234
247
|
return unless @options.dig(:cancel,:disconnect)
|
235
|
-
@notifier.log "
|
248
|
+
@notifier.log "#{identifier}: cancelled due to a connection error: #{error.to_s}", level: :debug
|
236
249
|
cancel error
|
237
250
|
end
|
238
251
|
|
@@ -265,5 +278,54 @@ module RSMP
|
|
265
278
|
end
|
266
279
|
true
|
267
280
|
end
|
281
|
+
|
282
|
+
# return a string that describes whe number of messages, and type of message we're collecting
|
283
|
+
def describe_num_and_type
|
284
|
+
if @options[:num] && @options[:num] > 1
|
285
|
+
"#{@options[:num]} #{@options[:type]}s"
|
286
|
+
else
|
287
|
+
@options[:type]
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
# return a string that describes the attributes that we're looking for
|
292
|
+
def describe_query
|
293
|
+
h = {component: @options[:component]}.compact
|
294
|
+
if h.empty?
|
295
|
+
describe_num_and_type
|
296
|
+
else
|
297
|
+
"#{describe_num_and_type} #{h}"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
# return a string that describe how many many messages have been collected
|
302
|
+
def describe_progress
|
303
|
+
if @options[:num]
|
304
|
+
"#{@messages.size} of #{@options[:num]} message#{'s' if @messages.size!=1} collected"
|
305
|
+
else
|
306
|
+
"#{@messages.size} message#{'s' if @messages.size!=1} collected"
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
# log when we start collecting
|
311
|
+
def log_start
|
312
|
+
@notifier.log "#{identifier}: Waiting for #{describe_query}".strip, level: :collect
|
313
|
+
end
|
314
|
+
|
315
|
+
# log current progress
|
316
|
+
def log_incomplete
|
317
|
+
@notifier.log "#{identifier}: #{describe_progress}", level: :collect
|
318
|
+
end
|
319
|
+
|
320
|
+
# log when we end collecting
|
321
|
+
def log_complete
|
322
|
+
@notifier.log "#{identifier}: Done", level: :collect
|
323
|
+
end
|
324
|
+
|
325
|
+
# get a short id in hex format, identifying ourself
|
326
|
+
def identifier
|
327
|
+
"Collect #{self.object_id.to_s(16)}"
|
328
|
+
end
|
329
|
+
|
268
330
|
end
|
269
331
|
end
|
@@ -97,8 +97,8 @@ module RSMP
|
|
97
97
|
matched = query.perform_match(item,message,@block)
|
98
98
|
return unless collecting?
|
99
99
|
if matched != nil
|
100
|
-
type = {true=>'match',false=>'mismatch'}[matched]
|
101
|
-
|
100
|
+
#type = {true=>'match',false=>'mismatch'}[matched]
|
101
|
+
#@notifier.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
|
102
102
|
if matched == true
|
103
103
|
query.keep message, item
|
104
104
|
elsif matched == false
|
@@ -107,8 +107,6 @@ module RSMP
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
|
-
complete if done?
|
111
|
-
@notifier.log "#{@title.capitalize} collect reached #{summary}", level: :debug
|
112
110
|
end
|
113
111
|
|
114
112
|
# don't collect anything. Query will collect them instead
|
@@ -118,5 +116,24 @@ module RSMP
|
|
118
116
|
def describe
|
119
117
|
@queries.map {|q| q.want.to_s }
|
120
118
|
end
|
119
|
+
|
120
|
+
# return a string that describes the attributes that we're looking for
|
121
|
+
def describe_query
|
122
|
+
want = @queries.map {|query| "#{query.want}" }
|
123
|
+
"#{super} with #{want.join(', ')}"
|
124
|
+
end
|
125
|
+
|
126
|
+
# return a string that describe how many many messages have been collected
|
127
|
+
def describe_progress
|
128
|
+
num_queries = @queries.size
|
129
|
+
num_matched = @queries.count { |query| query.done? }
|
130
|
+
|
131
|
+
got = @queries.select {|query| query.done? == true }.map {|query| "#{query.got}" }
|
132
|
+
need = @queries.select {|query| query.done? == false }.map {|query| "#{query.want}" }
|
133
|
+
str = "Matched #{num_matched} of #{num_queries}".colorize(:red)
|
134
|
+
str << ", got #{got.join(', ')}" if got.any?
|
135
|
+
str << ", need #{need.join(', ')}" if need.any?
|
136
|
+
str
|
137
|
+
end
|
121
138
|
end
|
122
139
|
end
|
data/lib/rsmp/logger.rb
CHANGED
@@ -135,12 +135,11 @@ module RSMP
|
|
135
135
|
colors = {
|
136
136
|
'info' => 'white',
|
137
137
|
'log' => 'light_blue',
|
138
|
-
'test' => 'light_magenta',
|
139
138
|
'statistics' => 'light_black',
|
140
|
-
'not_acknowledged' => 'cyan',
|
141
139
|
'warning' => 'light_yellow',
|
142
140
|
'error' => 'red',
|
143
|
-
'debug' => 'light_black'
|
141
|
+
'debug' => 'light_black',
|
142
|
+
'collect' => 'light_black'
|
144
143
|
}
|
145
144
|
colors.merge! @settings["color"] if @settings["color"].is_a?(Hash)
|
146
145
|
if colors[level.to_s]
|
data/lib/rsmp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Tin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async
|