redis-stream 0.4.2 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 198b2311a7fcf1023c8c51bb8ea96a6b6626a516539ba459005038703fbc430a
4
- data.tar.gz: 89c7601f9fcc02ebd0b195f8728231fba42a5a2f5f4ce60b749107f8a9c21c9e
3
+ metadata.gz: c68feb94f854987274b877134586cc49f146621d1bca1463dc7727c3d3330890
4
+ data.tar.gz: 3d0217743ed703c37bbe51c8fa69c89c0ee58749589d2edd3241c5950dae3447
5
5
  SHA512:
6
- metadata.gz: 0bc5a91481625900e58ff00614776c2eef887cec65e6b0aad5e1b05d74442309f6d37a2e605a5b45542dbd1179870552b6ac4076dc675136b01f0b26c8c9b900
7
- data.tar.gz: ab7ddb55e73a6f917ddd108499faff5c2ec69c96e7a861c63cafb32f9fc2040e66dd221babfd5d28098cba4c2abb2ef29752ab9e6eeb45d7f22bfc1acba9b79d
6
+ metadata.gz: 5b02a972747cf975360ceda206121f0dfd6e2dd12764eb1c7b90114785b932100b089629f19c7a09af5d49a0e648c775fd84400c2183cc0cdd5c0e2e2b2cf5de
7
+ data.tar.gz: 8816191f416792538278642d832d497e10cdcb3f4396ce9440825bad722a53a132111af3054f3d4289f5a0368726c7447d67e59c251f519de8a4ba7871cf34f1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redis-stream (0.4.1)
4
+ redis-stream (0.4.2)
5
5
  moneta (~> 1.2)
6
6
  multi_json (~> 1.14)
7
7
  redis (= 4.1.3)
@@ -80,18 +80,19 @@ class Redis
80
80
  # no passthrough variable here. The passthrough is available in the start method
81
81
  def add(data = {}, options = {})
82
82
  raise "Client isn't running" unless @state.eql?(Redis::Stream::State::RUNNING)
83
-
84
- default_options = {"to" => "*", "group" => "*", "type" => Redis::Stream::Type::ACTION, "cache_key" => nil, "tracer" => nil}
85
- options = default_options.merge(options)
86
-
87
- type = options["type"]
88
- to = options["to"]
89
- group = options["group"]
90
- payload = build_payload(data, options)
91
- add_id = @redis.xadd(@stream, payload)
92
- # @send_queue << add_id
93
-
94
- @logger.info("#{@consumer_id} - send to '#{to}' in group '#{group}' with id '#{add_id}' of type '#{type}'")
83
+ add_id = nil
84
+ OpenTracing.start_active_span('add') do |scope|
85
+ default_options = {"to" => "*", "group" => "*", "type" => Redis::Stream::Type::ACTION, "cache_key" => nil, "tracer" => nil}
86
+ options = default_options.merge(options)
87
+
88
+ type = options["type"]
89
+ to = options["to"]
90
+ group = options["group"]
91
+ payload = build_payload(data, options)
92
+ add_id = @redis.xadd(@stream, payload)
93
+
94
+ @logger.info("#{@consumer_id} - send to '#{to}' in group '#{group}' with id '#{add_id}' of type '#{type}'")
95
+ end
95
96
  add_id
96
97
  end
97
98
 
@@ -202,9 +203,6 @@ class Redis
202
203
  end
203
204
  end
204
205
 
205
- def trace_error(operation_name, span = nil)
206
- trace(operation_name, span)
207
- end
208
206
  private
209
207
 
210
208
  def build_payload(data, options)
@@ -304,61 +302,53 @@ class Redis
304
302
  # @param [Boolean] async return the message if synchronous else call handle_incoming
305
303
  # @param [Boolean] passthrough Receive all messages also the ones intended for other consumers
306
304
  def read_next_message_from_stream(async = true, passthrough = false)
307
- if @state == Redis::Stream::State::RUNNING
308
- result = @redis.xread(@stream, @lastid, block: 1000, count: 1) if @group.nil?
309
- result = @redis.xreadgroup(@group, @consumer_id, @stream, '>', block: 1000, count: 1) if @group
310
-
311
- unless result.empty?
312
- id, data_out = result[@stream][0]
313
- ack_count = @redis.xack(@stream, @group, id) if @group
314
-
315
- tracer_data = JSON.parse(data_out["tracer"])
316
- unless tracer_data.nil? || tracer_data.empty?
317
- tracer_span = OpenTracing.extract(OpenTracing::FORMAT_TEXT_MAP, tracer_data)
318
- data_out["tracer"] = OpenTracing.start_active_span(@consumer_id, child_of: tracer_span)
319
- end
305
+ if @state == Redis::Stream::State::RUNNING
306
+ result = @redis.xread(@stream, @lastid, block: 1000, count: 1) if @group.nil?
307
+ result = @redis.xreadgroup(@group, @consumer_id, @stream, '>', block: 1000, count: 1) if @group
308
+
309
+ unless result.empty?
310
+ id, data_out = result[@stream][0]
311
+ ack_count = @redis.xack(@stream, @group, id) if @group
312
+
313
+ tracer_data = JSON.parse(data_out["tracer"])
314
+ unless tracer_data.nil? || tracer_data.empty?
315
+ #trace_scope.span.log_kv('has_tracer' => true)
316
+ tracer_span = OpenTracing.extract(OpenTracing::FORMAT_TEXT_MAP, tracer_data)
317
+ data_out["tracer"] = OpenTracing.start_span(@consumer_id, child_of: tracer_span)
318
+ end
320
319
 
321
- begin
322
- data_out["payload"] = JSON.parse(data_out["payload"])
323
- rescue Exception => e
324
- @logger.error("#{@consumer_id} error parsing payload: #{e.message}")
325
- end
320
+ begin
321
+ data_out["payload"] = JSON.parse(data_out["payload"])
322
+ rescue Exception => e
323
+ @logger.error("#{@consumer_id} error parsing payload: #{e.message}")
324
+ end
326
325
 
327
- # if @send_queue.include?(id)
328
- # @send_queue.delete(id)
329
- # @logger.warning("#{@consumer_id} - send queue is not empty: #{@send_queue.join(',')}") if @send_queue.length > 0
330
- # unless passthrough
331
- # #@logger.info("#{@consumer_id} - ignoring self")
332
- # return false
333
- # end
334
- # end
335
-
336
- if data_out["from"].eql?(@consumer_id)
337
- return false
338
- end
326
+ if data_out["from"].eql?(@consumer_id)
327
+ return false
328
+ end
339
329
 
340
- unless (data_out["to"].nil? || data_out["to"].eql?('') || data_out["to"].eql?('*') || data_out["to"].eql?(@consumer_id)) &&
341
- (data_out["to_group"].nil? || data_out["to_group"].eql?('') || data_out["to_group"].eql?('*') || data_out["to_group"].eql?(@group))
342
- @logger.info("#{@consumer_id} - ignoring message from '#{data_out["from"]}' to '#{data_out["to"]}-#{data_out["to_group"]}'")
330
+ unless (data_out["to"].nil? || data_out["to"].eql?('') || data_out["to"].eql?('*') || data_out["to"].eql?(@consumer_id)) &&
331
+ (data_out["to_group"].nil? || data_out["to_group"].eql?('') || data_out["to_group"].eql?('*') || data_out["to_group"].eql?(@group))
332
+ @logger.info("#{@consumer_id} - ignoring message from '#{data_out["from"]}' to '#{data_out["to"]}-#{data_out["to_group"]}'")
343
333
 
344
- return false
345
- end
334
+ return false
335
+ end
346
336
 
347
- @logger.info("#{@consumer_id} - received from '#{data_out["from"]}' of type '#{data_out['type']}' to '#{data_out["to"]}' in group '#{data_out["to_group"]}' with message id '#{id}' - with ack #{ack_count}")
337
+ @logger.info("#{@consumer_id} - received from '#{data_out["from"]}' of type '#{data_out['type']}' to '#{data_out["to"]}' in group '#{data_out["to_group"]}' with message id '#{id}' - with ack #{ack_count}")
348
338
 
349
- if data_out["type"].eql?(Redis::Stream::Type::PING)
350
- add(data_out["payload"].to_s, "to" => data_out["from"], "group" => "*", "type" => Redis::Stream::Type::PONG)
351
- return false
352
- end
339
+ if data_out["type"].eql?(Redis::Stream::Type::PING)
340
+ add(data_out["payload"].to_s, "to" => data_out["from"], "group" => "*", "type" => Redis::Stream::Type::PONG)
341
+ return false
342
+ end
353
343
 
354
- if data_out["type"].eql?(Redis::Stream::Type::PONG)
355
- return false
356
- end
344
+ if data_out["type"].eql?(Redis::Stream::Type::PONG)
345
+ return false
346
+ end
357
347
 
358
- return data_out unless async
359
- handle_incoming(data_out)
348
+ return data_out unless async
349
+ handle_incoming(data_out)
350
+ end
360
351
  end
361
- end
362
352
  rescue Exception => e
363
353
  return false
364
354
  end
@@ -1,6 +1,6 @@
1
1
  #encoding: UTF-8
2
2
  class Redis
3
3
  module Stream
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.3"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mehmet Celik