rsmp 0.11.0 → 0.11.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1710b4aeba40d7f888921f76e2b09ffe5b7372f34d6e4360ccab5b7786b39ab
4
- data.tar.gz: 275ab0407885ed7b0b6aa1e3b12d257914ee09b6c1de65591189a88f07e40e93
3
+ metadata.gz: 3632282c6b535bc3d2355f4f572bea3179729dc89b3afa34f92aa57853e6e437
4
+ data.tar.gz: e64e7695d2b41f5f6c297b0c1a56c72ce8fb0bc5415f42e6026af5a8ae826dbe
5
5
  SHA512:
6
- metadata.gz: 171a4a1da3fe6a4b88a8efc48f51dbb78456261b41df943d77d1fbfb5df71568dd22978a0966d099e6e62bd870ad2ce252138df56790352d8647ab98039535f7
7
- data.tar.gz: 8829abe372e8dedeb8e81a79380ae62398e31814e96cd3e5e3f086db2d25d5dcd6127e628034bb04117e460d33600f7a5139380aebefb55289fadcb76555d73c
6
+ metadata.gz: c543a2e50e6894edeb003432050fae0b1ee9f8cc14814139156cf861ccc02d32b48b3fbec513723d610d453626330ea471bbdf0e937ccf28a80bb38d8ef3310a
7
+ data.tar.gz: 6d2e410152c264582d89efe5f08fe2f314d5848e4bc00bcc37d4e017e0cf85c17955f3604297a7972cdbfb55899105994a12206e996b92368fe53d826e02c0ab
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rsmp (0.11.0)
4
+ rsmp (0.11.4)
5
5
  async (~> 1.29.1)
6
6
  async-io (~> 1.32.2)
7
7
  colorize (~> 0.8.1)
@@ -9,6 +9,7 @@ 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
 
@@ -38,5 +39,11 @@ module RSMP
38
39
  end
39
40
  true
40
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
+
41
48
  end
42
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 begin unless ready (currenty #{@status})") unless ready?
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 "Collection cancelled due to schema error in #{klass} #{message.m_id_short}", level: :debug
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 "Collection cancelled due to a connection error: #{error.to_s}", level: :debug
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,59 @@ module RSMP
265
278
  end
266
279
  true
267
280
  end
281
+
282
+ # return a string describing the types of messages we're collecting
283
+ def describe_types
284
+ [@options[:type]].flatten.join('/')
285
+ end
286
+
287
+ # return a string that describes whe number of messages, and type of message we're collecting
288
+ def describe_num_and_type
289
+ if @options[:num] && @options[:num] > 1
290
+ "#{@options[:num]} #{describe_types}s"
291
+ else
292
+ describe_types
293
+ end
294
+ end
295
+
296
+ # return a string that describes the attributes that we're looking for
297
+ def describe_query
298
+ h = {component: @options[:component]}.compact
299
+ if h.empty?
300
+ describe_num_and_type
301
+ else
302
+ "#{describe_num_and_type} #{h}"
303
+ end
304
+ end
305
+
306
+ # return a string that describe how many many messages have been collected
307
+ def describe_progress
308
+ if @options[:num]
309
+ "#{@messages.size} of #{@options[:num]} message#{'s' if @messages.size!=1} collected"
310
+ else
311
+ "#{@messages.size} message#{'s' if @messages.size!=1} collected"
312
+ end
313
+ end
314
+
315
+ # log when we start collecting
316
+ def log_start
317
+ @notifier.log "#{identifier}: Waiting for #{describe_query}".strip, level: :collect
318
+ end
319
+
320
+ # log current progress
321
+ def log_incomplete
322
+ @notifier.log "#{identifier}: #{describe_progress}", level: :collect
323
+ end
324
+
325
+ # log when we end collecting
326
+ def log_complete
327
+ @notifier.log "#{identifier}: Done", level: :collect
328
+ end
329
+
330
+ # get a short id in hex format, identifying ourself
331
+ def identifier
332
+ "Collect #{self.object_id.to_s(16)}"
333
+ end
334
+
268
335
  end
269
336
  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
- @notifier.log "#{@title.capitalize} #{message.m_id_short} collect #{type} #{query.want}, item #{item}", level: :debug
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,98 @@ 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
+ "#{super} matching #{query_want_hash.to_s}"
123
+ end
124
+
125
+ # return a hash that describe the status of all queries
126
+ def progress_hash
127
+ h = {}
128
+ @queries.each do |query|
129
+ want = query.want
130
+ if want['cCI']
131
+ cCI = want['cCI']
132
+ h[cCI] ||= {}
133
+ cO = h['cO']
134
+ n = h['n']
135
+ v = h['v']
136
+ h[cCI][cO] ||= {}
137
+ h[cCI][cO][n] = v
138
+ elsif want['sCI']
139
+ sCI = want['sCI']
140
+ h[sCI] ||= {}
141
+ n = want['n']
142
+ s = want['s']
143
+ if query.got && query.got['s']
144
+ h[sCI][n] = { {s=>query.got['s']} => query.done? }
145
+ else
146
+ h[sCI][n] = { s=>nil }
147
+ end
148
+ end
149
+ end
150
+ h
151
+ end
152
+
153
+ # return a string that describe how many many messages have been collected
154
+ def describe_progress
155
+ num_queries = @queries.size
156
+ num_matched = @queries.count { |query| query.done? }
157
+ ".. Matched #{num_matched}/#{num_queries} with #{progress_hash.to_s}"
158
+ end
159
+
160
+ def query_want_hash
161
+ h = {}
162
+ @queries.each do |query|
163
+ item = query.want
164
+ if item['cCI']
165
+ cCI = item['cCI']
166
+ h[cCI] ||= {}
167
+ cO = item['cO']
168
+ h[cCI][cO] ||= {}
169
+ n = item['n']
170
+ v = item['v']
171
+ h[cCI][cO][n] = v || :any
172
+ elsif item['sCI']
173
+ sCI = item['sCI']
174
+ h[sCI] ||= {}
175
+ n = item['n']
176
+ s = item['s']
177
+ h[sCI][n] = s || :any
178
+ end
179
+ end
180
+ h
181
+ end
182
+
183
+ # return a hash that describe the end result
184
+ def query_got_hash
185
+ h = {}
186
+ @queries.each do |query|
187
+ want = query.want
188
+ got = query.got
189
+ if got['cCI']
190
+ cCI = want['cCI']
191
+ h[cCI] ||= {}
192
+ cO = want['cO']
193
+ h[cCI][cO] ||= {}
194
+ n = want['n']
195
+ v = got['v']
196
+ h[cCI][cO][n] = v
197
+ elsif want['sCI']
198
+ sCI = want['sCI']
199
+ h[sCI] ||= {}
200
+ n = want['n']
201
+ s = got['s']
202
+ h[sCI][n] = s
203
+ end
204
+ end
205
+ h
206
+ end
207
+
208
+ # log when we end collecting
209
+ def log_complete
210
+ @notifier.log "#{identifier}: Completed with #{query_got_hash.to_s}", level: :collect
211
+ end
121
212
  end
122
213
  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
@@ -1,3 +1,3 @@
1
1
  module RSMP
2
- VERSION = "0.11.0"
2
+ VERSION = "0.11.4"
3
3
  end
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.11.0
4
+ version: 0.11.4
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-21 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async