Class: Upfluence::Utils::Thrift::Middleware::Timeout
- Inherits:
-
Object
- Object
- Upfluence::Utils::Thrift::Middleware::Timeout
- Defined in:
- lib/upfluence/utils/thrift/middleware/timeout.rb
Instance Method Summary collapse
-
#initialize(app, duration) ⇒ Timeout
constructor
A new instance of Timeout.
- #method_missing(method, *args, &block) ⇒ Object
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 |