bug_bunny 4.1.0 → 4.1.1
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/CHANGELOG.md +10 -0
- data/lib/bug_bunny/consumer.rb +8 -2
- data/lib/bug_bunny/controller.rb +7 -12
- data/lib/bug_bunny/resource.rb +17 -2
- 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: 599004cdcb498ca746612f60202301ce9783a67ac37d14ecd4c29f51ccaf48bb
|
|
4
|
+
data.tar.gz: f748ba9a55e91f96a5571f671afa524f7e330cceede0f12c5c7cef6d25d2d2ff
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7df1503a55cb62d9f87168a84b8e92fe773b4c9525b143d6f848227e66fe63e5ab75f6191a408b00bb9c8840b44c0f8fdbc36cd0a8d2eb56e02018d09654d269
|
|
7
|
+
data.tar.gz: d5433d839c45ad95a2d0399535ff629112458e90d0e4e1ec89f97afa450b139bcb7855c64c27042c22bce0bde87b2bfa7bd6f8bae5b879dd7eb0c71ff1d20d3c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.1.1] - 2026-03-22
|
|
4
|
+
|
|
5
|
+
### 🐛 Bug Fixes
|
|
6
|
+
* **Consumer:** Previene memory leak al detener el `TimerTask` de health check previo antes de realizar una reconexión.
|
|
7
|
+
* **Controller:** Corrige la mutación accidental de \`log_tags\` globales al usar una lógica de herencia no destructiva en \`compute_tags\`.
|
|
8
|
+
|
|
9
|
+
### ✨ Improvements
|
|
10
|
+
* **Controller:** Ahora lanza una excepción \`BugBunny::BadRequest\` (400) si el cuerpo de la petición contiene un JSON inválido, mejorando la depuración en el cliente.
|
|
11
|
+
* **Resource:** Se añadió una protección a \`.with\` (\`ScopeProxy\`) para asegurar que el contexto sea de un solo uso, evitando efectos secundarios en llamadas encadenadas.
|
|
12
|
+
|
|
3
13
|
## [4.1.0] - 2026-03-22
|
|
4
14
|
|
|
5
15
|
### 🚀 New Features & Improvements
|
data/lib/bug_bunny/consumer.rb
CHANGED
|
@@ -44,6 +44,7 @@ module BugBunny
|
|
|
44
44
|
# @param connection [Bunny::Session] Conexión nativa de Bunny.
|
|
45
45
|
def initialize(connection)
|
|
46
46
|
@session = BugBunny::Session.new(connection)
|
|
47
|
+
@health_timer = nil
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
# Inicia la suscripción a la cola y comienza el bucle de procesamiento.
|
|
@@ -244,12 +245,16 @@ module BugBunny
|
|
|
244
245
|
# @param q_name [String] Nombre de la cola a monitorear.
|
|
245
246
|
# @return [void]
|
|
246
247
|
def start_health_check(q_name)
|
|
248
|
+
# Detener el timer anterior antes de crear uno nuevo (evita leak en cada retry)
|
|
249
|
+
@health_timer&.shutdown
|
|
250
|
+
@health_timer = nil
|
|
251
|
+
|
|
247
252
|
file_path = BugBunny.configuration.health_check_file
|
|
248
253
|
|
|
249
254
|
# Toque inicial para indicar al orquestador que el worker arrancó correctamente
|
|
250
255
|
touch_health_file(file_path) if file_path
|
|
251
256
|
|
|
252
|
-
Concurrent::TimerTask.new(execution_interval: BugBunny.configuration.health_check_interval) do
|
|
257
|
+
@health_timer = Concurrent::TimerTask.new(execution_interval: BugBunny.configuration.health_check_interval) do
|
|
253
258
|
# 1. Verificamos la salud de RabbitMQ (si falla, levanta un error y corta la ejecución del bloque)
|
|
254
259
|
session.channel.queue_declare(q_name, passive: true)
|
|
255
260
|
|
|
@@ -258,7 +263,8 @@ module BugBunny
|
|
|
258
263
|
rescue StandardError => e
|
|
259
264
|
BugBunny.configuration.logger.warn("[BugBunny::Consumer] ⚠️ Queue check failed: #{e.message}. Reconnecting session...")
|
|
260
265
|
session.close
|
|
261
|
-
end
|
|
266
|
+
end
|
|
267
|
+
@health_timer.execute
|
|
262
268
|
end
|
|
263
269
|
|
|
264
270
|
# Actualiza la fecha de modificación del archivo de health check (touchfile).
|
data/lib/bug_bunny/controller.rb
CHANGED
|
@@ -146,11 +146,6 @@ module BugBunny
|
|
|
146
146
|
def process(body)
|
|
147
147
|
prepare_params(body)
|
|
148
148
|
|
|
149
|
-
# Inyección de configuración global de logs si el controlador no define propios
|
|
150
|
-
if self.class.log_tags.empty? && BugBunny.configuration.log_tags.any?
|
|
151
|
-
self.class.log_tags = BugBunny.configuration.log_tags
|
|
152
|
-
end
|
|
153
|
-
|
|
154
149
|
action_name = headers[:action].to_sym
|
|
155
150
|
current_arounds = resolve_callbacks(self.class.around_actions, action_name)
|
|
156
151
|
|
|
@@ -245,12 +240,11 @@ module BugBunny
|
|
|
245
240
|
if body.is_a?(Hash)
|
|
246
241
|
params.merge!(body)
|
|
247
242
|
elsif body.is_a?(String) && headers[:content_type].to_s.include?('json')
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
params.merge!(parsed) if parsed
|
|
243
|
+
begin
|
|
244
|
+
params.merge!(JSON.parse(body))
|
|
245
|
+
rescue JSON::ParserError => e
|
|
246
|
+
raise BugBunny::BadRequest, "Invalid JSON in request body: #{e.message}"
|
|
247
|
+
end
|
|
254
248
|
else
|
|
255
249
|
self.raw_string = body
|
|
256
250
|
end
|
|
@@ -284,7 +278,8 @@ module BugBunny
|
|
|
284
278
|
end
|
|
285
279
|
|
|
286
280
|
def compute_tags
|
|
287
|
-
self.class.log_tags.
|
|
281
|
+
tags = self.class.log_tags.presence || BugBunny.configuration.log_tags
|
|
282
|
+
tags.map do |tag|
|
|
288
283
|
case tag
|
|
289
284
|
when Proc
|
|
290
285
|
tag.call(self)
|
data/lib/bug_bunny/resource.rb
CHANGED
|
@@ -154,9 +154,24 @@ module BugBunny
|
|
|
154
154
|
end
|
|
155
155
|
|
|
156
156
|
# Proxy para el encadenamiento del método `.with`.
|
|
157
|
+
# Solo puede usarse para UNA llamada de método: el contexto se restaura al finalizar.
|
|
157
158
|
class ScopeProxy < BasicObject
|
|
158
|
-
def initialize(target, keys, old_values)
|
|
159
|
-
|
|
159
|
+
def initialize(target, keys, old_values)
|
|
160
|
+
@target = target
|
|
161
|
+
@keys = keys
|
|
162
|
+
@old_values = old_values
|
|
163
|
+
@used = false
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def method_missing(method, *args, &block)
|
|
167
|
+
if @used
|
|
168
|
+
::Kernel.raise ::BugBunny::Error, "ScopeProxy is single-use. Call .with again for a new context."
|
|
169
|
+
end
|
|
170
|
+
@used = true
|
|
171
|
+
@target.public_send(method, *args, &block)
|
|
172
|
+
ensure
|
|
173
|
+
@keys.each { |k, v| ::Thread.current[v] = @old_values[k] }
|
|
174
|
+
end
|
|
160
175
|
end
|
|
161
176
|
|
|
162
177
|
# Calcula la routing key final.
|
data/lib/bug_bunny/version.rb
CHANGED