Class: JetstreamBridge::ConsumerMiddleware::MetricsMiddleware
- Inherits:
-
Object
- Object
- JetstreamBridge::ConsumerMiddleware::MetricsMiddleware
- Defined in:
- lib/jetstream_bridge/consumer/middleware.rb
Overview
Metrics middleware for tracking event processing
Instance Method Summary collapse
- #call(event) ⇒ Object
-
#initialize(on_success: nil, on_failure: nil) ⇒ MetricsMiddleware
constructor
A new instance of MetricsMiddleware.
Constructor Details
#initialize(on_success: nil, on_failure: nil) ⇒ MetricsMiddleware
95 96 97 98 |
# File 'lib/jetstream_bridge/consumer/middleware.rb', line 95 def initialize(on_success: nil, on_failure: nil) @on_success = on_success @on_failure = on_failure end |
Instance Method Details
#call(event) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/jetstream_bridge/consumer/middleware.rb', line 100 def call(event) start = Time.now yield duration = Time.now - start @on_success&.call(event, duration) rescue StandardError => e @on_failure&.call(event, e) raise end |