module Sidekiq::Util
This module is part of Sidekiq core and not intended for extensions.
Constants
- EXPIRY
Public Instance Methods
fire_event(event, reverse=false)
click to toggle source
# File lib/sidekiq/util.rb, line 49 def fire_event(event, reverse=false) arr = Sidekiq.options[:lifecycle_events][event] arr.reverse! if reverse arr.each do |block| begin block.call rescue => ex handle_exception(ex, { event: event }) end end arr.clear end
hostname()
click to toggle source
# File lib/sidekiq/util.rb, line 37 def hostname ENV['DYNO'] || Socket.gethostname end
identity()
click to toggle source
# File lib/sidekiq/util.rb, line 45 def identity @@identity ||= "#{hostname}:#{$$}:#{process_nonce}" end
logger()
click to toggle source
# File lib/sidekiq/util.rb, line 29 def logger Sidekiq.logger end
process_nonce()
click to toggle source
# File lib/sidekiq/util.rb, line 41 def process_nonce @@process_nonce ||= SecureRandom.hex(6) end
redis(&block)
click to toggle source
# File lib/sidekiq/util.rb, line 33 def redis(&block) Sidekiq.redis(&block) end
safe_thread(name, &block)
click to toggle source
# File lib/sidekiq/util.rb, line 23 def safe_thread(name, &block) Thread.new do watchdog(name, &block) end end
watchdog(last_words) { || ... }
click to toggle source
# File lib/sidekiq/util.rb, line 16 def watchdog(last_words) yield rescue Exception => ex handle_exception(ex, { context: last_words }) raise ex end