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