tiny_bus 3.6.0 → 3.7.1

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 +14 -6
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f68f0f35a09503b6ecd6fa7d914e5886b078ee18001bd79de12aaa06c54c9d11
4
- data.tar.gz: d8768af58ad92f7b0c38994833c095546f5d32ee63a709218633d2803a427d16
3
+ metadata.gz: 69976083efa62900031ef18daf5d222157fa8c2e1250a4fac06c8068a98631db
4
+ data.tar.gz: 3f428977292bfdbe108d859406b3f2359646a1e28e716779ce5b6c828a2a5e6a
5
5
  SHA512:
6
- metadata.gz: e9ec3f27c4da06841ecd727b15f0120f42efbce9848019a78e9d030921a4642734fd0d8d18c1fac92859c26fb7113d2be7ac409d3b2b6e998891ee1bdbbffaa7
7
- data.tar.gz: e6e5bfaf301ab9ff091788612b27f16a5ab02463234302ee567cf1845d14dc3d55328a978e79ba91abe2d94101ba46268ce57899e7b7a6e9ae66551d09b9c517
6
+ metadata.gz: df717813c4b3b516c6a2f16fdf539e2a8636a67a89a5c9b273640b721feaa37c16c69d9cd66198e8c36fbf322904384eac39987db3ae43d288e99da43c4b8b9b
7
+ data.tar.gz: d95a5ad0da6d327bd4c4586e4ee7ec9a9859a1c540a34a5f87ba9a9301280ff58822a9f805c54f499eb7d4ea18a18e7e309f30c67acb5c9a6c614caf79555a68
data/lib/tiny_bus.rb CHANGED
@@ -57,6 +57,7 @@ class TinyBus
57
57
  @subs = {}
58
58
  @translator = translator
59
59
 
60
+ @total_key = "#{annotation_prefix}total"
60
61
  @dead_key = "#{annotation_prefix}dead"
61
62
  @topic_key = "#{annotation_prefix}topic"
62
63
  @time_key = "#{annotation_prefix}time"
@@ -69,9 +70,9 @@ class TinyBus
69
70
  ->(m){ m[@trace_key] ||= SecureRandom.uuid; m }
70
71
  ])
71
72
 
72
- @stats = { '.dead' => 0 }
73
- @log = log || TinyLog.new($stdout)
74
- @dead = dead || TinyLog.new($stderr)
73
+ @stats = { @total_key => 0, @dead_key => 0 }
74
+ @log = log || TinyLog.new(filename: $stdout)
75
+ @dead = dead || TinyLog.new(filename: $stderr)
75
76
  @raise_on_dead = raise_on_dead
76
77
  end
77
78
 
@@ -114,11 +115,12 @@ class TinyBus
114
115
  msg = @translator&.pipe(msg) || msg
115
116
 
116
117
  topic = msg[@topic_key]
117
-
118
118
  subbers = @subs[topic]
119
119
 
120
+ @stats[topic] ||= 0
121
+ @stats[topic] += 1
122
+ @stats[@total_key] += 1
120
123
  if (subbers&.length || 0) > 0
121
- @stats[topic] += 1
122
124
  subbers.each{|s| s.msg(msg) }
123
125
  @log.send(lvl, "S #{msg}")
124
126
  else
@@ -131,12 +133,18 @@ class TinyBus
131
133
  end
132
134
  end
133
135
 
136
+ # returns a #dup of the internal statistics which track the number of
137
+ # messages sent to each topic, the dead queue, and total messages
138
+ def stats
139
+ @stats.dup
140
+ end
141
+
134
142
  # helpful for debugging, gives you a count of the number of messages sent to
135
143
  # each topic, including the .dead topic, which is where messages go where
136
144
  # there are no subscribes for a given topic
137
145
  def to_s
138
146
  <<~DEBUG
139
- TinyBus stats: #{@subs.keys.length > 0 ? "\n " + @stats.keys.sort.map{|t| "#{t.rjust(12)}: #{@stats[t]}" }.join("\n ") : '<NONE>'}
147
+ TinyBus stats: #{@stats.keys.length > 0 ? "\n " + @stats.keys.sort.map{|t| "#{t.rjust(12)}: #{@stats[t]}" }.join("\n ") : '<NONE>'}
140
148
  Topics & Subscribers:
141
149
  #{@subs.map{|topic, subbers| "#{topic}\n #{subbers.map(&:to_s).join("\n ")}" }.join("\n ") }
142
150
  DEBUG
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.0
4
+ version: 3.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-24 00:00:00.000000000 Z
11
+ date: 2023-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tiny_log
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  - !ruby/object:Gem::Version
65
65
  version: '0'
66
66
  requirements: []
67
- rubygems_version: 3.3.7
67
+ rubygems_version: 3.4.1
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: want to have an in-memory message bus that takes hash-like objects and distributes