Class: ActionSubscriber::Middleware::ErrorHandler
- Inherits:
-
Object
- Object
- ActionSubscriber::Middleware::ErrorHandler
- Includes:
- Logging
- Defined in:
- lib/action_subscriber/middleware/error_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Methods included from Logging
initialize_logger, logger, #logger, logger=
Constructor Details
#initialize(app) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
6 7 8 |
# File 'lib/action_subscriber/middleware/error_handler.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/action_subscriber/middleware/error_handler.rb', line 10 def call(env) job_mutex = ::Mutex.new job_complete = ::ConditionVariable.new job_mutex.synchronize do ::Thread.new do job_mutex.synchronize do begin @app.call(env) rescue => error logger.error "FAILED #{env.}" ::ActionSubscriber.configuration.error_handler.call(error, env.to_h) ensure job_complete.signal end end end # TODO we might want to pass a timeout to this wait so we can handle jobs that get frozen job_complete.wait(job_mutex) end end |