mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
64 lines
1.3 KiB
Ruby
64 lines
1.3 KiB
Ruby
require 'logger'
|
|
|
|
module Sidekiq
|
|
##
|
|
# This module is part of Sidekiq core and not intended for extensions.
|
|
#
|
|
module Util
|
|
|
|
def self.logger
|
|
@logger ||= begin
|
|
log = Logger.new(STDERR)
|
|
log.level = Logger::INFO
|
|
log
|
|
end
|
|
end
|
|
|
|
def self.logger=(log)
|
|
@logger = (log ? log : Logger.new('/dev/null'))
|
|
end
|
|
|
|
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
|
|
|
|
def watchdog(last_words)
|
|
yield
|
|
rescue => ex
|
|
logger.error last_words
|
|
logger.error ex
|
|
logger.error ex.backtrace.join("\n")
|
|
end
|
|
|
|
def logger
|
|
Sidekiq::Util.logger
|
|
end
|
|
|
|
def redis
|
|
Sidekiq.redis
|
|
end
|
|
|
|
def process_id
|
|
Sidekiq::Util.process_id
|
|
end
|
|
|
|
def self.process_id
|
|
@pid ||= begin
|
|
if Process.pid == 1
|
|
# Heroku does not expose pids.
|
|
require 'securerandom'
|
|
(SecureRandom.random_number * 4_000_000_000).floor.to_s(16)
|
|
else
|
|
Process.pid
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|