Class: JetstreamBridge::ConsumerMiddleware::TimeoutMiddleware
- Inherits:
-
Object
- Object
- JetstreamBridge::ConsumerMiddleware::TimeoutMiddleware
- Defined in:
- lib/jetstream_bridge/consumer/middleware.rb
Overview
Timeout middleware to prevent long-running handlers
Instance Method Summary collapse
- #call(event) ⇒ Object
-
#initialize(timeout: 30) ⇒ TimeoutMiddleware
constructor
A new instance of TimeoutMiddleware.
Constructor Details
#initialize(timeout: 30) ⇒ TimeoutMiddleware
138 139 140 |
# File 'lib/jetstream_bridge/consumer/middleware.rb', line 138 def initialize(timeout: 30) @timeout = timeout end |
Instance Method Details
#call(event) ⇒ Object
142 143 144 145 146 147 148 149 150 151 |
# File 'lib/jetstream_bridge/consumer/middleware.rb', line 142 def call(event, &) require 'timeout' Timeout.timeout(@timeout, &) rescue Timeout::Error raise ConsumerError.new( "Event processing timeout after #{@timeout}s", event_id: event.event_id, deliveries: event.deliveries ) end |