2018-03-15 12:00:53 -04:00
|
|
|
# frozen_string_literal: true
|
2019-04-01 12:20:41 -04:00
|
|
|
|
2017-01-04 13:30:42 -05:00
|
|
|
module Sidekiq
|
|
|
|
module Extensions
|
|
|
|
def self.enable_delay!
|
|
|
|
if defined?(::ActiveSupport)
|
2019-04-01 12:20:41 -04:00
|
|
|
require "sidekiq/extensions/active_record"
|
|
|
|
require "sidekiq/extensions/action_mailer"
|
2017-06-16 11:47:34 -04:00
|
|
|
|
|
|
|
# Need to patch Psych so it can autoload classes whose names are serialized
|
|
|
|
# in the delayed YAML.
|
|
|
|
Psych::Visitors::ToRuby.prepend(Sidekiq::Extensions::PsychAutoload)
|
|
|
|
|
2017-01-04 13:30:42 -05:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
|
|
|
include Sidekiq::Extensions::ActiveRecord
|
|
|
|
end
|
|
|
|
ActiveSupport.on_load(:action_mailer) do
|
|
|
|
extend Sidekiq::Extensions::ActionMailer
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-01 12:20:41 -04:00
|
|
|
require "sidekiq/extensions/class_methods"
|
2017-01-04 13:30:42 -05:00
|
|
|
Module.__send__(:include, Sidekiq::Extensions::Klass)
|
|
|
|
end
|
|
|
|
|
2017-06-16 11:47:34 -04:00
|
|
|
module PsychAutoload
|
|
|
|
def resolve_class(klass_name)
|
2017-07-29 02:26:44 -04:00
|
|
|
return nil if !klass_name || klass_name.empty?
|
2017-06-16 11:47:34 -04:00
|
|
|
# constantize
|
2019-04-01 12:20:41 -04:00
|
|
|
names = klass_name.split("::")
|
2017-06-16 11:47:34 -04:00
|
|
|
names.shift if names.empty? || names.first.empty?
|
|
|
|
|
|
|
|
names.inject(Object) do |constant, name|
|
|
|
|
constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
|
|
|
end
|
|
|
|
rescue NameError
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2017-01-04 13:30:42 -05:00
|
|
|
end
|
|
|
|
end
|