tiny_bus 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/lib/tiny_bus.rb +8 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 167d35639547e4dd4a52b2882a02926cc7cc1b1e73c0ef2affaca995190f70a3
|
4
|
+
data.tar.gz: 38326f77eba40699377e2b42f99e15484286c97028cdea5f35018d930f1fa18d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a588b106a52b799ab9c70f271ce2b4dc51fdac19f5b0518c53a95d5f5932b2eeda9ad53a5d61644e1d5aeba6ec0a0802540519ebbd21bc3e0c89f44ba8cd2ebd
|
7
|
+
data.tar.gz: 61f2606e77ea63a9638fadc926d9c8020db234946271ed829b4b6d4e3d09115c6c260f81fca86830df1681363e1d002731fc63cba058d0311d6ab497c019fd24
|
data/lib/tiny_bus.rb
CHANGED
@@ -20,9 +20,9 @@ require 'tiny_log'
|
|
20
20
|
# t.msg({'topic' => 'whatever', 'details' => 'Historic happenings!}) # goes to dead letter output, or raises exception, depending on the configuration
|
21
21
|
#
|
22
22
|
# Initialization options:
|
23
|
-
# TinyBus.new(log: <
|
24
|
-
# TinyBus.new(dead: <
|
25
|
-
# TinyBus.new(raise_on_dead: true)
|
23
|
+
# TinyBus.new(log: <a filename for log output>) # will log all normal msgs in this file
|
24
|
+
# TinyBus.new(dead: <a filename for dead message log output>) # will log all undeliverable msgs in this file
|
25
|
+
# TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
|
26
26
|
class TinyBus
|
27
27
|
# log:
|
28
28
|
# if specified it should be a valid filename
|
@@ -37,8 +37,8 @@ class TinyBus
|
|
37
37
|
def initialize(log: nil, dead: nil, raise_on_dead: false)
|
38
38
|
@subs = {}
|
39
39
|
@stats = { '.dead' => 0 }
|
40
|
-
@log = log ? TinyLog.new(log) : $stdout
|
41
|
-
@dead = dead ? File.open(dead, 'a') : $stderr
|
40
|
+
@log = log ? TinyLog.new(log) : TinyLog.new($stdout)
|
41
|
+
@dead = dead ? File.open(dead, 'a') : TinyLog.new($stderr)
|
42
42
|
@raise_on_dead = raise_on_dead
|
43
43
|
end
|
44
44
|
|
@@ -69,7 +69,7 @@ class TinyBus
|
|
69
69
|
#
|
70
70
|
# NOTE: it modifies the incoming msg object in place in order to avoid
|
71
71
|
# unnecessary object allocations
|
72
|
-
def msg(msg)
|
72
|
+
def msg(msg, lvl='info')
|
73
73
|
topic = msg['topic']
|
74
74
|
|
75
75
|
raise TinyBus::SendToDotTopicError.new("Cannot send to dot topic `#{topic}', because those are reserved for internal use") if topic.start_with?('.')
|
@@ -84,13 +84,13 @@ class TinyBus
|
|
84
84
|
if subbers
|
85
85
|
@stats[topic] += 1
|
86
86
|
subbers.each{|s| s.msg(annotated) }
|
87
|
-
@log.
|
87
|
+
@log.send(lvl, annotated)
|
88
88
|
else
|
89
89
|
if @raise_on_dead
|
90
90
|
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
|
91
91
|
else
|
92
92
|
@stats['.dead'] += 1
|
93
|
-
@dead.
|
93
|
+
@dead.send(lvl, annotated)
|
94
94
|
end
|
95
95
|
end
|
96
96
|
end
|