Module: Subserver::Util
- Includes:
- ExceptionHandler
- Defined in:
- lib/subserver/util.rb
Overview
This module is part of Subserver core and not intended for extensions.
Constant Summary collapse
- EXPIRY =
60 * 60 * 24
Instance Method Summary collapse
- #fire_event(event, options = {}) ⇒ Object
- #hostname ⇒ Object
- #identity ⇒ Object
- #logger ⇒ Object
- #process_nonce ⇒ Object
- #safe_thread(name, &block) ⇒ Object
- #watchdog(last_words) ⇒ Object
Methods included from ExceptionHandler
Instance Method Details
#fire_event(event, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/subserver/util.rb', line 45 def fire_event(event, ={}) reverse = [:reverse] reraise = [:reraise] arr = Subserver.[:lifecycle_events][event] arr.reverse! if reverse arr.each do |block| begin block.call rescue => ex handle_exception(ex, { context: "Exception during Subserver lifecycle event.", event: event }) raise ex if reraise end end arr.clear end |
#hostname ⇒ Object
33 34 35 |
# File 'lib/subserver/util.rb', line 33 def hostname ENV['DYNO'] || Socket.gethostname end |
#identity ⇒ Object
41 42 43 |
# File 'lib/subserver/util.rb', line 41 def identity @@identity ||= "#{hostname}:#{$$}:#{process_nonce}" end |
#process_nonce ⇒ Object
37 38 39 |
# File 'lib/subserver/util.rb', line 37 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end |
#safe_thread(name, &block) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/subserver/util.rb', line 22 def safe_thread(name, &block) Thread.new do Thread.current['subserver_label'] = name watchdog(name, &block) end end |
#watchdog(last_words) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/subserver/util.rb', line 15 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, { context: last_words }) raise ex end |