2012-08-02 20:46:06 -07:00
|
|
|
require 'sidekiq/exception_handler'
|
|
|
|
|
2012-01-22 11:32:38 -08:00
|
|
|
module Sidekiq
|
2012-02-17 13:39:36 -08:00
|
|
|
##
|
|
|
|
# This module is part of Sidekiq core and not intended for extensions.
|
|
|
|
#
|
2012-01-22 11:32:38 -08:00
|
|
|
module Util
|
2012-08-02 20:46:06 -07:00
|
|
|
include ExceptionHandler
|
2012-01-22 11:32:38 -08:00
|
|
|
|
2012-05-12 14:02:32 -07:00
|
|
|
EXPIRY = 60 * 60
|
2012-04-24 07:15:29 -07:00
|
|
|
|
2012-01-26 12:45:04 -08: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 11:32:38 -08:00
|
|
|
def watchdog(last_words)
|
|
|
|
yield
|
|
|
|
rescue => ex
|
2012-08-02 20:46:06 -07:00
|
|
|
handle_exception(ex, { :context => last_words })
|
2012-01-22 11:32:38 -08:00
|
|
|
end
|
|
|
|
|
2012-02-14 09:00:26 -08:00
|
|
|
def logger
|
2012-05-15 19:44:35 -07:00
|
|
|
Sidekiq.logger
|
2012-01-22 16:01:46 -08:00
|
|
|
end
|
2012-02-10 23:16:12 -08:00
|
|
|
|
2012-03-14 09:56:13 -07:00
|
|
|
def redis(&block)
|
|
|
|
Sidekiq.redis(&block)
|
2012-02-10 23:16:12 -08:00
|
|
|
end
|
2012-02-15 12:30:31 -08:00
|
|
|
|
|
|
|
def process_id
|
2012-03-06 20:18:16 -08:00
|
|
|
Process.pid
|
2012-02-15 12:30:31 -08:00
|
|
|
end
|
2012-01-22 11:32:38 -08:00
|
|
|
end
|
|
|
|
end
|