Class: Upfluence::Utils::Thrift::Middleware::Timeout

Inherits:
Object
  • Object
show all
Defined in:
lib/upfluence/utils/thrift/middleware/timeout.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, duration) ⇒ Timeout

Returns a new instance of Timeout.



6
7
8
9
# File 'lib/upfluence/utils/thrift/middleware/timeout.rb', line 6

def initialize(app, duration)
  @app = app
  @duration = duration
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/upfluence/utils/thrift/middleware/timeout.rb', line 11

def method_missing(method, *args, &block)
  ::Timeout.timeout(@duration) { @app.send(method, *args, &block) }
rescue ::Timeout::Error
  raise ::Thrift::ApplicationException.new(
    ::Thrift::ApplicationException::INTERNAL_ERROR,
    'Timeout reached'
  )
end