tiny_bus 3.2.0 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_bus.rb +8 -20
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0b4ee66f65bb60557ba29b72f0ade0e840f0db352ac2f1bca0cab5385b97b19
4
- data.tar.gz: '089bfc105f34f3538844e5756e3623f8db4f835c58501140cc6d6a02521c17dc'
3
+ metadata.gz: f3331fb500d2860aabc8902f7c9ca22afe2c9edf32225577ac22b41fe496e440
4
+ data.tar.gz: 637184ebeb5d80a614379af73b96b998d3e655844a4ac77f2427d407cc552c09
5
5
  SHA512:
6
- metadata.gz: 58a576c5b7bc7445b263e93b23ba1ba65e6536dfdd38dfe150251401dfc9490776ca6b751ef27c9ed71ce2bea0901d5292b009bed217c7c0a50c3c852f88e748
7
- data.tar.gz: 45a52d67eecda3efa9d8e72267413fd0d5adaab5b5f3168278e7938e0edd88f9f29b6e18fb5a98d7058c0a456c3898b83a92549cf7df7a012313bc27b1f8b736
6
+ metadata.gz: 2c49fe21fd0793a80914bc70d9c32c3fcc8e59fad61deae99f65a46ac122e6372e8eea2c2e0bea01afbb1e9cecb35929e6c3fee7b2d7beb8a7e1a0fbf12dfb1b
7
+ data.tar.gz: 732f63a9a8927a30a339a0214aede09ab23e532a7a1f379fd547f0f33cfcc637448433d785ad2c197572370f269fd71de65104bae84f6570b21dd380f4441492
data/lib/tiny_bus.rb CHANGED
@@ -28,10 +28,6 @@ require 'tiny_pipe'
28
28
  # TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
29
29
  class TinyBus
30
30
  ANNOTATION_PREFIX_DEFAULT = '.'
31
- LOGGING_LEVELS = {
32
- 'sent' => 'SENT',
33
- 'dead' => 'DEAD'
34
- }.freeze
35
31
 
36
32
  # log:
37
33
  # if specified, it should be a TinyLog instance
@@ -56,15 +52,8 @@ class TinyBus
56
52
  # default: '.'
57
53
  # if specified, the annotated message attributes ('.time', '.msg_uuid', and
58
54
  # '.trace') will have the dot ('.') replaced with the specified prefix text
59
- # logging_overrides:
60
- # default: LOGGING_LEVELS
61
- # allows you to specify a Hash of overrides of the logging levels for
62
- # 'SENT' and 'DEAD' message delivery; useful if the consuming application
63
- # wants to use its own logging levels, or you just want the labels changed
64
- # for some reason
65
55
  def initialize(log: nil, dead: nil, translator: nil, raise_on_dead: false,
66
- annotation_prefix: ANNOTATION_PREFIX_DEFAULT,
67
- logging_overrides: LOGGING_LEVELS)
56
+ annotation_prefix: ANNOTATION_PREFIX_DEFAULT)
68
57
  @subs = {}
69
58
  @translator = translator
70
59
 
@@ -75,8 +64,8 @@ class TinyBus
75
64
  @trace_key = "#{annotation_prefix}trace"
76
65
 
77
66
  @annotator = TinyPipe.new([
78
- ->(m){ m[@time_key] = (Time.now.to_f * 1000).to_i; m },
79
- ->(m){ m[@msg_uuid_key] = SecureRandom.uuid; m },
67
+ ->(m){ m[@time_key] ||= (Time.now.to_f * 1000).to_i; m },
68
+ ->(m){ m[@msg_uuid_key] ||= SecureRandom.uuid; m },
80
69
  ->(m){ m[@trace_key] ||= SecureRandom.uuid; m }
81
70
  ])
82
71
 
@@ -84,8 +73,6 @@ class TinyBus
84
73
  @log = log || TinyLog.new($stdout)
85
74
  @dead = dead || TinyLog.new($stderr)
86
75
  @raise_on_dead = raise_on_dead
87
- @sent_level = logging_overrides['sent'] || LOGGING_LEVELS['sent']
88
- @dead_level = logging_overrides['dead'] || LOGGING_LEVELS['dead']
89
76
  end
90
77
 
91
78
  # adds a subscriber to a topic
@@ -110,9 +97,10 @@ class TinyBus
110
97
  #
111
98
  # msg: the incoming message to be distributed
112
99
  # lvl (optional): the logging level
100
+ # default: 'info'
113
101
  #
114
- # NOTE: it modifies the incoming msg object in place in order to avoid
115
- # unnecessary object allocations
102
+ # NOTE: this method modifies the incoming msg object in place in order to
103
+ # avoid unnecessary object allocations
116
104
  #
117
105
  # NOTE: keys that begin with dot (.), such as '.time' are reserved for
118
106
  # TinyBus and show not be altered by outside code, otherwise undefined
@@ -128,13 +116,13 @@ class TinyBus
128
116
  if (subbers&.length || 0) > 0
129
117
  @stats[topic] += 1
130
118
  subbers.each{|s| s.msg(msg) }
131
- @log.send(@sent_level, msg)
119
+ @log.send(lvl, "S #{msg}")
132
120
  else
133
121
  if @raise_on_dead
134
122
  raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
135
123
  else
136
124
  @stats[@dead_key] += 1
137
- @dead.send(@dead_level, msg)
125
+ @dead.send(lvl, "D #{msg}")
138
126
  end
139
127
  end
140
128
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt