mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Use core_ext for constantize and stringify_keys
This commit is contained in:
parent
ad03228cb6
commit
f04e1ecbec
4 changed files with 35 additions and 21 deletions
|
@ -51,4 +51,34 @@ rescue LoadError
|
|||
end
|
||||
end
|
||||
|
||||
begin
|
||||
require 'active_support/core_ext/hash/keys'
|
||||
rescue LoadError
|
||||
class Hash
|
||||
def stringify_keys(hash)
|
||||
hash.keys.each do |key|
|
||||
hash[key.to_s] = hash.delete(key)
|
||||
end
|
||||
hash
|
||||
end
|
||||
end if !{}.responds_to(:stringify_keys)
|
||||
end
|
||||
|
||||
begin
|
||||
require 'active_support/core_ext/string/inflections'
|
||||
rescue LoadError
|
||||
class String
|
||||
def constantize
|
||||
names = self.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
|
||||
end if !"".responds_to(:constantize)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ module Sidekiq
|
|||
defer do
|
||||
begin
|
||||
msg = Sidekiq.load_json(msgstr)
|
||||
klass = constantize(msg['class'])
|
||||
klass = msg['class'].constantize
|
||||
worker = klass.new
|
||||
|
||||
stats(worker, msg, queue) do
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
require 'socket'
|
||||
require 'sidekiq/exception_handler'
|
||||
require 'sidekiq/core_ext'
|
||||
|
||||
module Sidekiq
|
||||
##
|
||||
|
@ -10,17 +11,6 @@ module Sidekiq
|
|||
|
||||
EXPIRY = 60 * 60 * 24
|
||||
|
||||
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 Exception => ex
|
||||
|
|
|
@ -31,6 +31,7 @@ module Sidekiq
|
|||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def perform_async(*args)
|
||||
client_push('class' => self, 'args' => args)
|
||||
end
|
||||
|
@ -52,7 +53,7 @@ module Sidekiq
|
|||
# :backtrace - whether to save any error backtrace in the retry payload to display in web UI,
|
||||
# can be true, false or an integer number of lines to save, default *false*
|
||||
def sidekiq_options(opts={})
|
||||
self.sidekiq_options_hash = get_sidekiq_options.merge(stringify_keys(opts || {}))
|
||||
self.sidekiq_options_hash = get_sidekiq_options.merge((opts || {}).stringify_keys)
|
||||
end
|
||||
|
||||
DEFAULT_OPTIONS = { 'retry' => true, 'queue' => 'default' }
|
||||
|
@ -61,15 +62,8 @@ module Sidekiq
|
|||
self.sidekiq_options_hash ||= DEFAULT_OPTIONS
|
||||
end
|
||||
|
||||
def stringify_keys(hash) # :nodoc:
|
||||
hash.keys.each do |key|
|
||||
hash[key.to_s] = hash.delete(key)
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
def client_push(item) # :nodoc:
|
||||
Sidekiq::Client.push(stringify_keys(item))
|
||||
Sidekiq::Client.push(item.stringify_keys)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue