tiny_bus 3.1.1 → 3.3.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_bus.rb +18 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27b59f1cbc599aa563486a8fb29274e2369b1099dc01523f96b14bc9f3f0d06f
4
- data.tar.gz: e8f3511275ca57d791808e343e9f70e4855cbaea72a1eb119935b09b4acbbb4e
3
+ metadata.gz: b6166f18cf5222d5886b6276f55e5e6eba9f74050f69665a93b1f641a0ae9177
4
+ data.tar.gz: 96b2ebda14a8820f268d19c1f7e517937fae4c424faf8cb31bcf20a6b87110e3
5
5
  SHA512:
6
- metadata.gz: adfd193f7b1c3f55c66f86d5a096d21b0d1d8e5fb04c2c978cf9885cdb8663ca3d2850dfda25c4debb4b93e5407dd601428f76a184a72f7a1210b0abf7a2ce03
7
- data.tar.gz: 34c31596855df2ac266fd839de02b84c1827cc64ec4ecf2d295cf98748364604be1285c9b0efb9278392fadadd23553d5d342cb76f9b67a037c12c51443361c0
6
+ metadata.gz: b95b706827023d4cbd94030a3f5a382d46543422e6ad47f9bfe2196972c0c106b22082a5654b096de708ccdba8d7d48be949c11b59a1a8ec89162eeec2d6e471
7
+ data.tar.gz: b7be435794e5fc4aca6f4baa0ab3b7d35ceaebdd573fe1e60bb7ff5757370917a96c3b4b0ea476796ba2f3e46326e2b524e06d64705f890f4f533c761253c5f4
data/lib/tiny_bus.rb CHANGED
@@ -28,6 +28,10 @@ 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
31
35
 
32
36
  # log:
33
37
  # if specified, it should be a TinyLog instance
@@ -52,8 +56,15 @@ class TinyBus
52
56
  # default: '.'
53
57
  # if specified, the annotated message attributes ('.time', '.msg_uuid', and
54
58
  # '.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
55
65
  def initialize(log: nil, dead: nil, translator: nil, raise_on_dead: false,
56
- annotation_prefix: ANNOTATION_PREFIX_DEFAULT)
66
+ annotation_prefix: ANNOTATION_PREFIX_DEFAULT,
67
+ logging_overrides: LOGGING_LEVELS)
57
68
  @subs = {}
58
69
  @translator = translator
59
70
 
@@ -64,8 +75,8 @@ class TinyBus
64
75
  @trace_key = "#{annotation_prefix}trace"
65
76
 
66
77
  @annotator = TinyPipe.new([
67
- ->(m){ m[@time_key] = (Time.now.to_f * 1000).to_i; m },
68
- ->(m){ m[@msg_uuid_key] = SecureRandom.uuid; m },
78
+ ->(m){ m[@time_key] ||= (Time.now.to_f * 1000).to_i; m },
79
+ ->(m){ m[@msg_uuid_key] ||= SecureRandom.uuid; m },
69
80
  ->(m){ m[@trace_key] ||= SecureRandom.uuid; m }
70
81
  ])
71
82
 
@@ -73,6 +84,8 @@ class TinyBus
73
84
  @log = log || TinyLog.new($stdout)
74
85
  @dead = dead || TinyLog.new($stderr)
75
86
  @raise_on_dead = raise_on_dead
87
+ @sent_level = logging_overrides['sent'] || LOGGING_LEVELS['sent']
88
+ @dead_level = logging_overrides['dead'] || LOGGING_LEVELS['dead']
76
89
  end
77
90
 
78
91
  # adds a subscriber to a topic
@@ -115,13 +128,13 @@ class TinyBus
115
128
  if (subbers&.length || 0) > 0
116
129
  @stats[topic] += 1
117
130
  subbers.each{|s| s.msg(msg) }
118
- @log.sent msg
131
+ @log.send(@sent_level, msg)
119
132
  else
120
133
  if @raise_on_dead
121
134
  raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
122
135
  else
123
136
  @stats[@dead_key] += 1
124
- @dead.dead msg
137
+ @dead.send(@dead_level, msg)
125
138
  end
126
139
  end
127
140
  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.1.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt