Module: Sidekiq::Util
- Includes:
- ExceptionHandler
- Defined in:
- lib/sidekiq/util.rb
Constant Summary collapse
- PAUSE_TIME =
hack for quicker development / testing environment #2774
$stdout.tty? ? 0.1 : 0.5
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
-
#wait_for(deadline, &condblock) ⇒ Object
Wait for the orblock to be true or the deadline passed.
- #watchdog(last_words) ⇒ Object
Methods included from ExceptionHandler
Instance Method Details
#fire_event(event, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sidekiq/util.rb', line 93 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
81 82 83 |
# File 'lib/sidekiq/util.rb', line 81 def hostname ENV["DYNO"] || Socket.gethostname end |
#identity ⇒ Object
89 90 91 |
# File 'lib/sidekiq/util.rb', line 89 def identity @@identity ||= "#{hostname}:#{::Process.pid}:#{process_nonce}" end |
#process_nonce ⇒ Object
85 86 87 |
# File 'lib/sidekiq/util.rb', line 85 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end |
#redis(&block) ⇒ Object
73 74 75 |
# File 'lib/sidekiq/util.rb', line 73 def redis(&block) Sidekiq.redis(&block) end |
#safe_thread(name, &block) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/sidekiq/util.rb', line 62 def safe_thread(name, &block) Thread.new do Thread.current.name = name watchdog(name, &block) end end |
#tid ⇒ Object
77 78 79 |
# File 'lib/sidekiq/util.rb', line 77 def tid Thread.current["sidekiq_tid"] ||= (Thread.current.object_id ^ ::Process.pid).to_s(36) end |
#wait_for(deadline, &condblock) ⇒ Object
Wait for the orblock to be true or the deadline passed.
46 47 48 49 50 51 52 53 |
# File 'lib/sidekiq/util.rb', line 46 def wait_for(deadline, &condblock) remaining = deadline - ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) while remaining > PAUSE_TIME return if condblock.call sleep PAUSE_TIME remaining = deadline - ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) end end |
#watchdog(last_words) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/sidekiq/util.rb', line 55 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, {context: last_words}) raise ex end |