Module: Sidekiq::Util

Overview

This module is part of Sidekiq core and not intended for extensions.

Defined Under Namespace

Classes: Pretty

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.loggerObject


17
18
19
20
21
22
23
24
# File 'lib/sidekiq/util.rb', line 17

def self.logger
  @logger ||= begin
    log = Logger.new(STDOUT)
    log.level = Logger::INFO
    log.formatter = Pretty.new
    log
  end
end

.logger=(log) ⇒ Object


26
27
28
# File 'lib/sidekiq/util.rb', line 26

def self.logger=(log)
  @logger = (log ? log : Logger.new('/dev/null'))
end

Instance Method Details

#constantize(camel_cased_word) ⇒ Object


30
31
32
33
34
35
36
37
38
39
# File 'lib/sidekiq/util.rb', line 30

def constantize(camel_cased_word)
  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
  end
  constant
end

#loggerObject


49
50
51
# File 'lib/sidekiq/util.rb', line 49

def logger
  Sidekiq::Util.logger
end

#process_idObject


57
58
59
# File 'lib/sidekiq/util.rb', line 57

def process_id
  Process.pid
end

#redis(&block) ⇒ Object


53
54
55
# File 'lib/sidekiq/util.rb', line 53

def redis(&block)
  Sidekiq.redis(&block)
end

#watchdog(last_words) ⇒ Object


41
42
43
44
45
46
47
# File 'lib/sidekiq/util.rb', line 41

def watchdog(last_words)
  yield
rescue => ex
  logger.error last_words
  logger.error ex
  logger.error ex.backtrace.join("\n")
end