Module: TaskTempest::ErrorHandling
- Included in:
- Engine
- Defined in:
- lib/task_tempest/error_handling.rb
Constant Summary collapse
- SHUTDOWN_EXCEPTIONS =
[ Interrupt, SystemExit, SignalException ]
Instance Method Summary collapse
- #format_exception(e) ⇒ Object
- #handle_shutdown_signal(e) ⇒ Object
- #with_error_handling(error_action = :continue) ⇒ Object
- #with_shutdown_handling ⇒ Object
Instance Method Details
#format_exception(e) ⇒ Object
53 54 55 |
# File 'lib/task_tempest/error_handling.rb', line 53 def format_exception(e) "#{e.class}: #{e.}\n" + e.backtrace.join("\n") end |
#handle_shutdown_signal(e) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/task_tempest/error_handling.rb', line 40 def handle_shutdown_signal(e) case e. when "SIGTERM" logger.info "SIGTERM detected" dirty_shutdown when "SIGUSR2" logger.info "SIGUSR2 detected" clean_shutdown else false end end |
#with_error_handling(error_action = :continue) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/task_tempest/error_handling.rb', line 10 def with_error_handling(error_action = :continue) yield rescue *SHUTDOWN_EXCEPTIONS => e raise rescue Exception => e on_internal_exception(e) case error_action when :halt logger.fatal format_exception(e) exit(-1) when :reraise logger.fatal format_exception(e) raise when :continue logger.error format_exception(e) else raise "Wtf man, typo." end end |
#with_shutdown_handling ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/task_tempest/error_handling.rb', line 30 def with_shutdown_handling yield rescue *SHUTDOWN_EXCEPTIONS => e if e.class == SignalException handle_shutdown_signal(e) or raise else clean_shutdown end end |