tiny_bus 3.5.0 → 3.7.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 +14 -4
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36e46c0df98b592b75546fb9949dce3b7ab566b36d2d45c2ad7875359ab20f6c
4
- data.tar.gz: e82f99237803f759d119522db17eb7a8bf671bc6e74994442b74afe2aa22b941
3
+ metadata.gz: 10175a5f3eb8391e273b860aefdccd67ff469fb603a063fecdeb58858af6066b
4
+ data.tar.gz: 2b2a8e6babff0734b57f0b91e2d12bd0782133e0291f4a561441969815deed0e
5
5
  SHA512:
6
- metadata.gz: ad7aa85c1d1054f68a8575421df286a7050a06f25798ef14c2ce9e0531d9d75dad9d99e1132503e49b46342b535abffe0aba8f42d6680e52d6d58ef6ce176f07
7
- data.tar.gz: '03549a8c7363c88acff29cc86c7a2e9ce17f9beb94c324b8385e59614c6e7cdbdd764a0020a1627a2c7ff82d37617a1871600107e37d5dd6447aae0d8a8ea7aa'
6
+ metadata.gz: 9b1a67cd7b2d5a5e9a93f245c4f9f5b14c70edfcb99a0c64d0b145f3b4349865db668846b5cc9399fbf32f6ddf9ea399f245232535c999c4f8a65754ca9545e0
7
+ data.tar.gz: 0a22452c404f6e61664b2ce84b4b21f8b686537625c8bbb43c38294e2303262bdab72482d92025f88be4e3a23eac1004a39b1c59850303d01aa76c7d656213df
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
 
@@ -117,6 +118,7 @@ class TinyBus
117
118
 
118
119
  subbers = @subs[topic]
119
120
 
121
+ @stats[@total_key] += 1
120
122
  if (subbers&.length || 0) > 0
121
123
  @stats[topic] += 1
122
124
  subbers.each{|s| s.msg(msg) }
@@ -131,12 +133,20 @@ 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>'}
148
+ Topics & Subscribers:
149
+ #{@subs.map{|topic, subbers| "#{topic}\n #{subbers.map(&:to_s).join("\n ")}" }.join("\n ") }
140
150
  DEBUG
141
151
  end
142
152
  end
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.5.0
4
+ version: 3.7.0
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-21 00:00:00.000000000 Z
11
+ date: 2023-07-04 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