Class: JetstreamBridge::ConsumerMiddleware::TimeoutMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/jetstream_bridge/consumer/middleware.rb

Overview

Timeout middleware to prevent long-running handlers

Examples:

consumer.use(JetstreamBridge::Consumer::TimeoutMiddleware.new(timeout: 30))

Instance Method Summary collapse

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