tiny_bus 3.3.0 → 3.4.1

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 +8 -20
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6166f18cf5222d5886b6276f55e5e6eba9f74050f69665a93b1f641a0ae9177
4
- data.tar.gz: 96b2ebda14a8820f268d19c1f7e517937fae4c424faf8cb31bcf20a6b87110e3
3
+ metadata.gz: 6d3c857478866a08cee5481b5e6673e1113e796975cb050587a6ae7231c0071f
4
+ data.tar.gz: 62360c6eda4448a72b3465321742920b7438e274817266b43ff408c014b73771
5
5
  SHA512:
6
- metadata.gz: b95b706827023d4cbd94030a3f5a382d46543422e6ad47f9bfe2196972c0c106b22082a5654b096de708ccdba8d7d48be949c11b59a1a8ec89162eeec2d6e471
7
- data.tar.gz: b7be435794e5fc4aca6f4baa0ab3b7d35ceaebdd573fe1e60bb7ff5757370917a96c3b4b0ea476796ba2f3e46326e2b524e06d64705f890f4f533c761253c5f4
6
+ metadata.gz: c48c7344e5506fb4ab40475167b2b6b2b6a6ab8a991222437e67f16bab9b5b3ad131256295552596679635b00a7b7278461c58dad5632f2b04fa696ff2d7f9b4
7
+ data.tar.gz: dfe686720994f643787e7847a594296006643668696e54b4dfd8d9f372d6f2692839c7fa8a758eac7fefb282896cb3a6134628c8705ce8ded4e4ab033af32d7a
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
 
@@ -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
@@ -96,23 +83,24 @@ class TinyBus
96
83
  @subs[topic] << subber
97
84
  @stats[topic] ||= 0
98
85
 
99
- msg({ @topic_key => 'sub', 'to_topic' => topic, 'subber' => subber.to_s })
86
+ msg({ @topic_key => 'sub', 'to_topic' => topic, 'subber' => subber.to_s }, 'TINYBUS-SUB')
100
87
  end
101
88
 
102
89
  # removes a subscriber from a topic
103
90
  def unsub(topic, subber)
104
91
  @subs[topic]&.delete(subber)
105
92
 
106
- msg({ @topic_key => 'unsub', 'from_topic' => topic, 'subber' => subber.to_s })
93
+ msg({ @topic_key => 'unsub', 'from_topic' => topic, 'subber' => subber.to_s }, 'TINYBUS-UNSUB')
107
94
  end
108
95
 
109
96
  # takes an incoming message and distributes it to subscribers
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.3.0
4
+ version: 3.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt