tiny_bus 3.7.2 → 3.8.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 +13 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 803568daf9dd822ea55895b457386681ca10188a55fc23e906837b3fbce106fa
4
- data.tar.gz: 9377bf6ace10208f47140c30df9ac826d9fa268e668da1bc589d143cb2571366
3
+ metadata.gz: 38ce7566363b86a218bb2860573779d5737e6051bc34b78051ca0f20d737ada1
4
+ data.tar.gz: af3d2e8f729655b6907793580c20024ff94c3fb5bda862266623c78c94d35dbf
5
5
  SHA512:
6
- metadata.gz: ec5d4689105f2b985f79906e7ed027dea7409b3d75077c9ce71b8e8ee7d48b30e8f5b10a81ff8f9335a7ce0996e5a0fd71dfaf3c5f8c140c36987e97ef61e692
7
- data.tar.gz: 92cedd46357367de1ce95e830f835d483cec6c765576c34e93facf4f711ec353255205ce4ba2d51b545ca5b8f03f9563ac3ad6042e321d2162a0947355f58be7
6
+ metadata.gz: a4e70298e41c92c63bdd3dc88ac487ab301823aba258198cae8ea10256170fec4c08ac9ba7bc2acfa722c1c57c933858d07302b8f2ef4fac2ba57c21ee5d4a77
7
+ data.tar.gz: bc01af0b3a2a97770972103424f0220f20629eed25e0ae1613029b09a8b14083c39233d7ac52faf13576771b57358885cc325160f54fa95ad7518b7a745221d4
data/lib/tiny_bus.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'set'
1
2
  require 'time'
2
3
  require 'set'
3
4
  require 'securerandom'
@@ -29,6 +30,8 @@ require 'tiny_pipe'
29
30
  class TinyBus
30
31
  ANNOTATION_PREFIX_DEFAULT = '.'
31
32
 
33
+ attr_reader :dead_topics
34
+
32
35
  # log:
33
36
  # if specified, it should be a TinyLog instance
34
37
  # if not specified, it will create a new TinyLog instance for $stdout
@@ -55,6 +58,7 @@ class TinyBus
55
58
  def initialize(log: nil, dead: nil, translator: nil, raise_on_dead: false,
56
59
  annotation_prefix: ANNOTATION_PREFIX_DEFAULT)
57
60
  @subs = {}
61
+ @dead_topics = Set.new
58
62
  @translator = translator
59
63
 
60
64
  @total_key = "#{annotation_prefix}total"
@@ -80,6 +84,7 @@ class TinyBus
80
84
  def sub(topic, subber)
81
85
  raise TinyBus::SubscriberDoesNotMsg.new("The specified subscriber type `#{subber.class.inspect}' does not respond to #msg") unless subber.respond_to?(:msg)
82
86
 
87
+ @dead_topics.delete(topic)
83
88
  @subs[topic] ||= Set.new
84
89
  @subs[topic] << subber
85
90
  @stats[topic] ||= 0
@@ -90,6 +95,7 @@ class TinyBus
90
95
  # removes a subscriber from a topic
91
96
  def unsub(topic, subber)
92
97
  @subs[topic]&.delete(subber)
98
+ @dead_topics << topic if @subs[topic].empty?
93
99
 
94
100
  msg({ @topic_key => 'unsub', 'from_topic' => topic, 'subber' => _to_subber_id(subber) }, 'TINYBUS-UNSUB')
95
101
  end
@@ -128,6 +134,7 @@ class TinyBus
128
134
  raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
129
135
  else
130
136
  @stats[@dead_key] += 1
137
+ @dead_topics << topic
131
138
  @dead.send(lvl, "D #{msg}")
132
139
  end
133
140
  end
@@ -144,9 +151,12 @@ class TinyBus
144
151
  # there are no subscribes for a given topic
145
152
  def to_s
146
153
  <<~DEBUG
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 ") }
154
+ TinyBus stats: #{@stats.keys.length > 0 ? "\n " + @stats.keys.sort.map{|t| "#{t.rjust(12)}: #{@stats[t]}" }.join("\n ") : '<NONE>'}
155
+ Dead topics: [
156
+ #{@dead_topics.sort.each_slice(3).map{|slice| slice.join(', ') }.join("\n ")}
157
+ ]
158
+ Topics & Subscribers:
159
+ #{@subs.map{|topic, subbers| "#{topic}:\n #{subbers.map(&:to_s).join("\n ")}" }.join("\n ") }
150
160
  DEBUG
151
161
  end
152
162
  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.7.2
4
+ version: 3.8.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: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tiny_log