2012-01-22 14:32:38 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Util
|
|
|
|
|
2012-01-26 15:45:04 -05:00
|
|
|
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
|
|
|
|
|
2012-01-22 14:32:38 -05:00
|
|
|
def watchdog(last_words)
|
|
|
|
yield
|
|
|
|
rescue => ex
|
2012-02-10 00:46:44 -05:00
|
|
|
err last_words
|
|
|
|
err ex
|
|
|
|
err ex.backtrace.join("\n")
|
2012-01-22 14:32:38 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def err(msg)
|
|
|
|
STDERR.puts(msg)
|
|
|
|
end
|
|
|
|
|
|
|
|
def log(msg)
|
2012-02-03 13:02:57 -05:00
|
|
|
STDOUT.puts(msg) unless $TESTING
|
2012-01-22 14:32:38 -05:00
|
|
|
end
|
|
|
|
|
2012-01-22 19:01:46 -05:00
|
|
|
def verbose(msg)
|
|
|
|
STDOUT.puts(msg) if $DEBUG
|
|
|
|
end
|
2012-02-11 02:16:12 -05:00
|
|
|
|
|
|
|
def redis
|
2012-02-11 16:14:03 -05:00
|
|
|
Sidekiq::Manager.redis
|
2012-02-11 02:16:12 -05:00
|
|
|
end
|
2012-01-22 14:32:38 -05:00
|
|
|
end
|
|
|
|
end
|