lepus 0.2.0 → 0.2.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/.github/workflows/linter.yml +1 -1
- data/.github/workflows/specs.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -0
- data/gemfiles/Gemfile.rails-5.2.lock +1 -1
- data/gemfiles/Gemfile.rails-6.1.lock +1 -1
- data/gemfiles/Gemfile.rails-7.2.lock +1 -1
- data/gemfiles/Gemfile.rails-8.0.lock +1 -1
- data/lib/lepus/consumer.rb +35 -19
- data/lib/lepus/rails/log_subscriber.rb +8 -0
- data/lib/lepus/version.rb +1 -1
- data/lib/lepus.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8cf7f4418578e3ab6600df2c9de267e134311af605a96db80f7b0f746763096d
|
|
4
|
+
data.tar.gz: 469fda46acebe440afe6ecca36e78b7b4395c520bc789ed90183553c3eb78ed7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed0693421c238ba690ad399d072449920d73fdc63ec2437095ce8d8352bdf5aabfb65517ce34ed5aaae06fe68fa45aefa55dd31a3c1a743e5f80e43b3dbaad18
|
|
7
|
+
data.tar.gz: 4fc5b7a1735979b94c94b7d6a6fd6979bf84c3479e19ec0661ba355c604af9233f218bf735dca9990a4d31197b468185506739c1f17b5618a2ffc664c39d3a43
|
data/.github/workflows/specs.yml
CHANGED
|
@@ -8,7 +8,7 @@ on:
|
|
|
8
8
|
|
|
9
9
|
jobs:
|
|
10
10
|
ruby-2-7:
|
|
11
|
-
runs-on: ubuntu-
|
|
11
|
+
runs-on: ubuntu-24.04
|
|
12
12
|
strategy:
|
|
13
13
|
fail-fast: false
|
|
14
14
|
matrix:
|
|
@@ -32,7 +32,7 @@ jobs:
|
|
|
32
32
|
run: bundle exec rspec
|
|
33
33
|
|
|
34
34
|
ruby-3-0:
|
|
35
|
-
runs-on: ubuntu-
|
|
35
|
+
runs-on: ubuntu-24.04
|
|
36
36
|
strategy:
|
|
37
37
|
fail-fast: false
|
|
38
38
|
matrix:
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## 0.2.1 - 2026-10-30
|
|
8
|
+
* Added: `process_delivery.lepus` instrumentation around every consumed message, with consumer, exchange, routing key, redelivered flag and result
|
|
9
|
+
* Added: `consumer_error.lepus` instrumentation when `#perform` raises, before the message is rejected
|
|
10
|
+
* Added: `Lepus::LogSubscriber` logs processed deliveries (info) and consumer errors (error)
|
|
11
|
+
* Fixed: `Lepus.instrument` without a block no longer raises when ActiveSupport is not loaded
|
|
12
|
+
|
|
7
13
|
## 0.2.0 - 2026-10-28
|
|
8
14
|
* Added: named producer connections via `config.connection(name, url:, **bunny_options)`; `rabbitmq_url` remains the `:default` connection
|
|
9
15
|
* Added: `connection:` option on `Producer.configure`, `Producer.publish` and `Lepus::Publisher.new`, with one producer connection pool per name
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -567,6 +567,15 @@ bundle exec lepus start MyConsumer1 MyConsumer2 --debug
|
|
|
567
567
|
|
|
568
568
|
Each consumer will run in a separate process, and a supervisor will monitor them. If a consumer crashes, the supervisor will restart it.
|
|
569
569
|
|
|
570
|
+
### Instrumentation and logging
|
|
571
|
+
|
|
572
|
+
Every consumed message emits a `process_delivery.lepus` event (`consumer`, `exchange`, `routing_key`, `redelivered`, `result`), and an exception raised by `#perform` emits `consumer_error.lepus` (with `error`) before the message is rejected. In Rails, `Lepus::LogSubscriber` logs both to `Lepus.logger`:
|
|
573
|
+
|
|
574
|
+
```
|
|
575
|
+
Lepus-0.2.1 Processed OrdersConsumer (12.3ms) exchange: "orders", routing_key: "orders.created", redelivered: false, result: :ack
|
|
576
|
+
Lepus-0.2.1 Error in OrdersConsumer (0.0ms) exchange: "orders", routing_key: "orders.created", redelivered: false, error: "RuntimeError boom"
|
|
577
|
+
```
|
|
578
|
+
|
|
570
579
|
### Puma Plugin
|
|
571
580
|
|
|
572
581
|
We provide a Puma plugin if you want to run the Lepus's supervisor together with Puma and have Puma monitor and manage it. You just need to add
|
data/lib/lepus/consumer.rb
CHANGED
|
@@ -98,26 +98,9 @@ module Lepus
|
|
|
98
98
|
message = Message.coerce(delivery_info, metadata, payload)
|
|
99
99
|
message.consumer_class = self.class
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
self.class.middleware_chain
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
combined_chain.execute(message) do |msg|
|
|
107
|
-
perform(msg).tap do |result|
|
|
108
|
-
verify_result(result)
|
|
109
|
-
end
|
|
101
|
+
Lepus.instrument(:process_delivery, **delivery_attributes(delivery_info)) do |event|
|
|
102
|
+
event[:result] = deliver(message, delivery_info)
|
|
110
103
|
end
|
|
111
|
-
rescue Lepus::InvalidConsumerReturnError
|
|
112
|
-
raise
|
|
113
|
-
rescue Exception # rubocop:disable Lint/RescueException
|
|
114
|
-
on_delivery_error
|
|
115
|
-
# In testing mode, re-raise exceptions if consumer_raise_errors? is enabled
|
|
116
|
-
if defined?(Lepus::Testing) && Lepus::Testing.consumer_raise_errors?
|
|
117
|
-
raise
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
reject!
|
|
121
104
|
end
|
|
122
105
|
|
|
123
106
|
# Returns whether the last delivery resulted in an error.
|
|
@@ -194,6 +177,39 @@ module Lepus
|
|
|
194
177
|
def on_delivery_error
|
|
195
178
|
end
|
|
196
179
|
|
|
180
|
+
def deliver(message, delivery_info)
|
|
181
|
+
combined_chain = MiddlewareChain.combine(
|
|
182
|
+
Lepus.config.consumer_middleware_chain,
|
|
183
|
+
self.class.middleware_chain
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
combined_chain.execute(message) do |msg|
|
|
187
|
+
perform(msg).tap do |result|
|
|
188
|
+
verify_result(result)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
rescue Lepus::InvalidConsumerReturnError
|
|
192
|
+
raise
|
|
193
|
+
rescue Exception => error # rubocop:disable Lint/RescueException
|
|
194
|
+
Lepus.instrument(:consumer_error, error: error, **delivery_attributes(delivery_info))
|
|
195
|
+
on_delivery_error
|
|
196
|
+
# In testing mode, re-raise exceptions if consumer_raise_errors? is enabled
|
|
197
|
+
if defined?(Lepus::Testing) && Lepus::Testing.consumer_raise_errors?
|
|
198
|
+
raise
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
reject!
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def delivery_attributes(delivery_info)
|
|
205
|
+
{
|
|
206
|
+
consumer: self.class.name,
|
|
207
|
+
exchange: delivery_info&.exchange,
|
|
208
|
+
routing_key: delivery_info&.routing_key,
|
|
209
|
+
redelivered: delivery_info&.redelivered
|
|
210
|
+
}
|
|
211
|
+
end
|
|
212
|
+
|
|
197
213
|
def verify_result(result)
|
|
198
214
|
return if %i[ack reject requeue nack].include?(result)
|
|
199
215
|
|
|
@@ -100,6 +100,14 @@ class Lepus::LogSubscriber < ActiveSupport::LogSubscriber
|
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
+
def process_delivery(event)
|
|
104
|
+
info formatted_event(event, action: "Processed #{event.payload[:consumer]}", **event.payload.slice(:exchange, :routing_key, :redelivered, :result))
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def consumer_error(event)
|
|
108
|
+
error formatted_event(event, action: "Error in #{event.payload[:consumer]}", **event.payload.slice(:exchange, :routing_key, :redelivered), error: formatted_error(event.payload[:error]))
|
|
109
|
+
end
|
|
110
|
+
|
|
103
111
|
private
|
|
104
112
|
|
|
105
113
|
def formatted_event(event, action:, **attributes)
|
data/lib/lepus/version.rb
CHANGED
data/lib/lepus.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lepus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcos G. Zimmermann
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exec
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|