diff --git a/lib/sidekiq.rb b/lib/sidekiq.rb index 81a50977..ab68fa4a 100644 --- a/lib/sidekiq.rb +++ b/lib/sidekiq.rb @@ -227,6 +227,16 @@ module Sidekiq # DO NOT RESCUE THIS ERROR IN YOUR WORKERS class Shutdown < Interrupt; end + def self.constantize(str) + names = str.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 require 'sidekiq/rails' if defined?(::Rails::Engine) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index af0f5455..c1d887be 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -134,7 +134,7 @@ module Sidekiq # the Reloader. It handles code loading, db connection management, etc. # Effectively this block denotes a "unit of work" to Rails. @reloader.call do - klass = Sidekiq::Util.constantize(job_hash['class'.freeze]) + klass = Sidekiq.constantize(job_hash['class'.freeze]) worker = klass.new worker.jid = job_hash['jid'.freeze] @retrier.local(worker, job_hash, queue) do diff --git a/lib/sidekiq/testing.rb b/lib/sidekiq/testing.rb index 760f0941..451c057c 100644 --- a/lib/sidekiq/testing.rb +++ b/lib/sidekiq/testing.rb @@ -76,7 +76,7 @@ module Sidekiq true elsif Sidekiq::Testing.inline? payloads.each do |job| - klass = Sidekiq::Util.constantize(job['class']) + klass = Sidekiq.constantize(job['class']) job['id'] ||= SecureRandom.hex(12) job_hash = Sidekiq.load_json(Sidekiq.dump_json(job)) klass.process_job(job_hash) @@ -309,7 +309,7 @@ module Sidekiq worker_classes = jobs.map { |job| job["class"] }.uniq worker_classes.each do |worker_class| - Sidekiq::Util.constantize(worker_class).drain + Sidekiq.constantize(worker_class).drain end end end diff --git a/lib/sidekiq/util.rb b/lib/sidekiq/util.rb index 691bbece..9b6baa37 100644 --- a/lib/sidekiq/util.rb +++ b/lib/sidekiq/util.rb @@ -60,15 +60,5 @@ module Sidekiq arr.clear end - def self.constantize(str) - names = str.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 end