bug_bunny 2.0.1 → 2.0.2
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/bug_bunny/exception.rb +1 -0
- data/lib/bug_bunny/publisher.rb +13 -20
- data/lib/bug_bunny/rabbit.rb +4 -0
- data/lib/bug_bunny/resource.rb +22 -8
- data/lib/bug_bunny/version.rb +1 -1
- 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: 8fccb3590fd16133119a7e2cea4c05002964846ac5a35e0714925f2d87115a06
|
|
4
|
+
data.tar.gz: 839ab64bb406eebee8e59f99c010c640a033dab15cd0f531e66f0fbc1e201c82
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4be8016e660aec70394814ffc85ecba71759aeb94df817abac412c201685ebee89c447fdd76b9904dfb5d2bc5f73e208ed0eed2d9bbc016a307c09978254c76e
|
|
7
|
+
data.tar.gz: 741552a099ae0aadb5717cb46fc4ff24c77c9f31f7dae677131dc158f784a75bca1a739bb6cf65eba42bff84fba853d25a2df54ca0d5884a23f679fa72c679b0
|
data/lib/bug_bunny/exception.rb
CHANGED
data/lib/bug_bunny/publisher.rb
CHANGED
|
@@ -52,7 +52,7 @@ module BugBunny
|
|
|
52
52
|
include ActiveModel::Attributes
|
|
53
53
|
|
|
54
54
|
attribute :message
|
|
55
|
-
attribute :
|
|
55
|
+
attribute :connection
|
|
56
56
|
attribute :routing_key, :string
|
|
57
57
|
attribute :persistent, :boolean, default: false
|
|
58
58
|
attribute :content_type, :string, default: "application/json"
|
|
@@ -66,25 +66,19 @@ module BugBunny
|
|
|
66
66
|
attribute :expiration, :integer, default: -> { 1.day.in_milliseconds } #ms
|
|
67
67
|
attribute :exchange_name, :string
|
|
68
68
|
attribute :exchange_type, :string, default: 'direct'
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
attribute :type, :string
|
|
71
70
|
attribute :action, :string
|
|
72
|
-
attribute :arguments, default: {}
|
|
73
71
|
|
|
74
72
|
def publish!
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
app.publish!(message, publish_opts)
|
|
79
|
-
end
|
|
73
|
+
app = Rabbit.new(connection: connection)
|
|
74
|
+
app.build_exchange(name: exchange_name, type: exchange_type)
|
|
75
|
+
app.publish!(message, publish_opts)
|
|
80
76
|
end
|
|
81
77
|
|
|
82
78
|
def publish_and_consume!
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
app.publish_and_consume!(message, publish_opts)
|
|
87
|
-
end
|
|
79
|
+
app = Rabbit.new(connection: connection)
|
|
80
|
+
app.build_exchange(name: exchange_name, type: exchange_type)
|
|
81
|
+
app.publish_and_consume!(message, publish_opts)
|
|
88
82
|
end
|
|
89
83
|
|
|
90
84
|
def publish_opts
|
|
@@ -101,14 +95,13 @@ module BugBunny
|
|
|
101
95
|
expiration: expiration }
|
|
102
96
|
end
|
|
103
97
|
|
|
104
|
-
def type
|
|
105
|
-
return if action.blank?
|
|
106
|
-
|
|
107
|
-
self.type = format(action, arguments)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
98
|
def initialize(attrs = {})
|
|
111
99
|
super(attrs)
|
|
100
|
+
if attrs[:action].present?
|
|
101
|
+
args = attrs[:arguments] || {}
|
|
102
|
+
|
|
103
|
+
self.type = format(attrs[:action], args)
|
|
104
|
+
end
|
|
112
105
|
self.routing_key ||= self.class::ROUTING_KEY
|
|
113
106
|
end
|
|
114
107
|
end
|
data/lib/bug_bunny/rabbit.rb
CHANGED
|
@@ -303,6 +303,10 @@ module BugBunny
|
|
|
303
303
|
)
|
|
304
304
|
|
|
305
305
|
bunny.tap(&:start)
|
|
306
|
+
rescue Timeout::Error, Bunny::ConnectionError => e
|
|
307
|
+
# Timeout::Error (para el timeout de conexión TCP) se captura separadamente.
|
|
308
|
+
# Bunny::ConnectionError cubre TCPConnectionFailed, AuthenticationFailure, AccessRefused, etc.
|
|
309
|
+
raise BugBunny::Error::Connection, e.message
|
|
306
310
|
end
|
|
307
311
|
end
|
|
308
312
|
end
|
data/lib/bug_bunny/resource.rb
CHANGED
|
@@ -21,16 +21,18 @@ module BugBunny
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
class ExchangeScope
|
|
24
|
-
attr_reader :exchange_name, :klass
|
|
24
|
+
attr_reader :exchange_name, :routing_key, :klass
|
|
25
25
|
|
|
26
|
-
def initialize(klass, exchange_name)
|
|
26
|
+
def initialize(klass, exchange_name, routing_key = nil)
|
|
27
27
|
@klass = klass
|
|
28
28
|
@exchange_name = exchange_name
|
|
29
|
+
@routing_key = routing_key
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
def method_missing(method_name, *args, **kwargs, &block)
|
|
32
33
|
if @klass.respond_to?(method_name, true)
|
|
33
34
|
kwargs[:exchange] = @exchange_name
|
|
35
|
+
kwargs[:routing_key] = @routing_key if @routing_key.present?
|
|
34
36
|
@klass.execute(method_name.to_sym, *args, **kwargs, &block)
|
|
35
37
|
else
|
|
36
38
|
super
|
|
@@ -103,7 +105,7 @@ module BugBunny
|
|
|
103
105
|
|
|
104
106
|
return self if persisted? && changes.empty?
|
|
105
107
|
|
|
106
|
-
obj = self.class.publisher.send(action, exchange: current_exchange, message: changes_to_send)
|
|
108
|
+
obj = self.class.publisher.send(action, exchange: current_exchange, routing_key: current_routing_key, message: changes_to_send)
|
|
107
109
|
|
|
108
110
|
assign_attributes(obj) # refresco el objeto
|
|
109
111
|
self.persisted = true
|
|
@@ -119,7 +121,7 @@ module BugBunny
|
|
|
119
121
|
return self unless persisted?
|
|
120
122
|
|
|
121
123
|
# Llamada al PUBLISHER sin el argumento 'box'
|
|
122
|
-
self.class.publisher.send(destroy_action.to_sym, exchange: current_exchange, id: id)
|
|
124
|
+
self.class.publisher.send(destroy_action.to_sym, exchange: current_exchange, routing_key: current_routing_key, id: id)
|
|
123
125
|
|
|
124
126
|
self.persisted = false
|
|
125
127
|
true
|
|
@@ -132,20 +134,28 @@ module BugBunny
|
|
|
132
134
|
self.class.current_exchange
|
|
133
135
|
end
|
|
134
136
|
|
|
135
|
-
def
|
|
137
|
+
def current_routing_key
|
|
138
|
+
self.class.current_routing_key
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def self.for_exchange(exchange_name, routing_key = nil)
|
|
136
142
|
raise ArgumentError, 'Exchange name must be specified.' if exchange_name.blank?
|
|
137
143
|
|
|
138
|
-
ExchangeScope.new(self, exchange_name)
|
|
144
|
+
ExchangeScope.new(self, exchange_name, routing_key)
|
|
139
145
|
end
|
|
140
146
|
|
|
141
147
|
def self.execute(name, *args, **kwargs, &block)
|
|
142
148
|
original_exchange = Thread.current[:bugbunny_current_exchange]
|
|
143
149
|
Thread.current[:bugbunny_current_exchange] = kwargs[:exchange]
|
|
150
|
+
original_routing_key = Thread.current[:bugbunny_current_routing_key]
|
|
151
|
+
Thread.current[:bugbunny_current_routing_key] = kwargs[:routing_key]
|
|
144
152
|
begin
|
|
145
153
|
kwargs.delete(:exchange)
|
|
154
|
+
kwargs.delete(:routing_key)
|
|
146
155
|
send(name, *args, **kwargs, &block)
|
|
147
156
|
ensure
|
|
148
157
|
Thread.current[:bugbunny_current_exchange] = original_exchange
|
|
158
|
+
Thread.current[:bugbunny_current_routing_key] = original_routing_key
|
|
149
159
|
end
|
|
150
160
|
end
|
|
151
161
|
|
|
@@ -153,12 +163,16 @@ module BugBunny
|
|
|
153
163
|
Thread.current[:bugbunny_current_exchange]
|
|
154
164
|
end
|
|
155
165
|
|
|
166
|
+
def self.current_routing_key
|
|
167
|
+
Thread.current[:bugbunny_current_routing_key]
|
|
168
|
+
end
|
|
169
|
+
|
|
156
170
|
def self.all
|
|
157
171
|
where
|
|
158
172
|
end
|
|
159
173
|
|
|
160
174
|
def self.where(query = {})
|
|
161
|
-
body = publisher.send(index_action.to_sym, exchange: current_exchange, message: query)
|
|
175
|
+
body = publisher.send(index_action.to_sym, exchange: current_exchange, routing_key: current_routing_key, message: query)
|
|
162
176
|
instances = []
|
|
163
177
|
|
|
164
178
|
body.each do |obj|
|
|
@@ -171,7 +185,7 @@ module BugBunny
|
|
|
171
185
|
end
|
|
172
186
|
|
|
173
187
|
def self.find(id)
|
|
174
|
-
obj = publisher.send(show_action.to_sym, exchange: current_exchange, id: id)
|
|
188
|
+
obj = publisher.send(show_action.to_sym, exchange: current_exchange, routing_key: current_routing_key, id: id)
|
|
175
189
|
return if obj.blank?
|
|
176
190
|
|
|
177
191
|
instance = new
|
data/lib/bug_bunny/version.rb
CHANGED