Module: Sidekiq::Util
- Includes:
- ExceptionHandler
- Defined in:
- lib/sidekiq/util.rb
Overview
This module is part of Sidekiq core and not intended for extensions.
Instance Method Summary collapse
- #fire_event(event, options = {}) ⇒ Object
- #hostname ⇒ Object
- #identity ⇒ Object
- #logger ⇒ Object
- #process_nonce ⇒ Object
- #redis(&block) ⇒ Object
- #safe_thread(name, &block) ⇒ Object
- #tid ⇒ Object
- #watchdog(last_words) ⇒ Object
Methods included from ExceptionHandler
Instance Method Details
#fire_event(event, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sidekiq/util.rb', line 52 def fire_event(event, = {}) reverse = [:reverse] reraise = [:reraise] arr = Sidekiq.[:lifecycle_events][event] arr.reverse! if reverse arr.each do |block| block.call rescue => ex handle_exception(ex, {context: "Exception during Sidekiq lifecycle event.", event: event}) raise ex if reraise end arr.clear end |
#hostname ⇒ Object
40 41 42 |
# File 'lib/sidekiq/util.rb', line 40 def hostname ENV["DYNO"] || Socket.gethostname end |
#identity ⇒ Object
48 49 50 |
# File 'lib/sidekiq/util.rb', line 48 def identity @@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}" end |
#process_nonce ⇒ Object
44 45 46 |
# File 'lib/sidekiq/util.rb', line 44 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end |
#redis(&block) ⇒ Object
32 33 34 |
# File 'lib/sidekiq/util.rb', line 32 def redis(&block) Sidekiq.redis(&block) end |
#safe_thread(name, &block) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/sidekiq/util.rb', line 21 def safe_thread(name, &block) Thread.new do Thread.current.name = name watchdog(name, &block) end end |
#tid ⇒ Object
36 37 38 |
# File 'lib/sidekiq/util.rb', line 36 def tid Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36) end |
#watchdog(last_words) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/sidekiq/util.rb', line 14 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, {context: last_words}) raise ex end |