Module: Sidekiq::Util
- Includes:
- ExceptionHandler
- Included in:
- CLI, Fetcher, Launcher, Manager, Middleware::Server::RetryJobs, Processor, Scheduled::Poller
- Defined in:
- lib/sidekiq/util.rb
Overview
This module is part of Sidekiq core and not intended for extensions.
Constant Summary collapse
- EXPIRY =
60 * 60 * 24
Instance Method Summary collapse
- #fire_event(event, reverse = false) ⇒ Object
- #hostname ⇒ Object
- #identity ⇒ Object
- #logger ⇒ Object
- #process_nonce ⇒ Object
- #redis(&block) ⇒ Object
- #want_a_hertz_donut? ⇒ Boolean
- #watchdog(last_words) ⇒ Object
Methods included from ExceptionHandler
Instance Method Details
#fire_event(event, reverse = false) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sidekiq/util.rb', line 42 def fire_event(event, reverse=false) arr = Sidekiq.[:lifecycle_events][event] arr.reverse! if reverse arr.each do |block| begin block.call rescue => ex handle_exception(ex, { event: event }) end end end |
#hostname ⇒ Object
30 31 32 |
# File 'lib/sidekiq/util.rb', line 30 def hostname ENV['DYNO'] || Socket.gethostname end |
#identity ⇒ Object
38 39 40 |
# File 'lib/sidekiq/util.rb', line 38 def identity @@identity ||= "#{hostname}:#{$$}:#{process_nonce}" end |
#process_nonce ⇒ Object
34 35 36 |
# File 'lib/sidekiq/util.rb', line 34 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end |
#redis(&block) ⇒ Object
26 27 28 |
# File 'lib/sidekiq/util.rb', line 26 def redis(&block) Sidekiq.redis(&block) end |
#want_a_hertz_donut? ⇒ Boolean
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/sidekiq/util.rb', line 54 def want_a_hertz_donut? # what's a hertz donut? # punch! Hurts, don't it? info = Sidekiq.redis {|c| c.info } if info['connected_clients'].to_i > 1000 && info['hz'].to_i >= 10 Sidekiq.logger.warn { "Your Redis `hz` setting is too high at #{info['hz']}. See mperham/sidekiq#2431. Set it to 3 in #{info[:config_file]}" } true else Sidekiq.logger.debug { "Redis hz: #{info['hz']}. Client count: #{info['connected_clients']}" } false end end |
#watchdog(last_words) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/sidekiq/util.rb', line 15 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, { context: last_words }) raise ex end |