2012-01-25 16:32:51 -05:00
|
|
|
module Sidekiq
|
2012-03-10 15:30:15 -05:00
|
|
|
def self.hook_rails!
|
2014-06-28 18:19:42 -04:00
|
|
|
return if defined?(@delay_removed)
|
|
|
|
|
2014-03-28 20:36:38 -04:00
|
|
|
ActiveSupport.on_load(:active_record) do
|
|
|
|
include Sidekiq::Extensions::ActiveRecord
|
2012-03-10 15:30:15 -05:00
|
|
|
end
|
|
|
|
|
2014-03-28 20:36:38 -04:00
|
|
|
ActiveSupport.on_load(:action_mailer) do
|
|
|
|
extend Sidekiq::Extensions::ActionMailer
|
2012-03-10 15:30:15 -05:00
|
|
|
end
|
2014-06-28 18:19:42 -04:00
|
|
|
|
|
|
|
Module.__send__(:include, Sidekiq::Extensions::Klass)
|
2012-03-10 15:30:15 -05:00
|
|
|
end
|
|
|
|
|
2014-04-24 10:11:05 -04:00
|
|
|
# Removes the generic aliases which MAY clash with names of already
|
|
|
|
# created methods by other applications. The methods `sidekiq_delay`,
|
|
|
|
# `sidekiq_delay_for` and `sidekiq_delay_until` can be used instead.
|
2014-05-20 23:42:25 -04:00
|
|
|
def self.remove_delay!
|
2014-06-28 18:19:42 -04:00
|
|
|
@delay_removed = true
|
|
|
|
|
2014-05-20 23:42:25 -04:00
|
|
|
[Extensions::ActiveRecord,
|
|
|
|
Extensions::ActionMailer,
|
2014-04-24 10:11:05 -04:00
|
|
|
Extensions::Klass].each do |mod|
|
|
|
|
mod.module_eval do
|
|
|
|
remove_method :delay if respond_to?(:delay)
|
|
|
|
remove_method :delay_for if respond_to?(:delay_for)
|
|
|
|
remove_method :delay_until if respond_to?(:delay_until)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-25 16:32:51 -05:00
|
|
|
class Rails < ::Rails::Engine
|
2012-03-10 15:30:15 -05:00
|
|
|
initializer 'sidekiq' do
|
|
|
|
Sidekiq.hook_rails!
|
|
|
|
end
|
2016-02-01 18:59:20 -05:00
|
|
|
|
|
|
|
class Reloader
|
|
|
|
def initialize(app = ::Rails.application)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
ActiveSupport::Dependencies.interlock.running do
|
|
|
|
begin
|
|
|
|
ActionDispatch::Reloader.prepare! if do_reload_now = reload_dependencies?
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
ActionDispatch::Reloader.cleanup! if do_reload_now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reload_dependencies?
|
|
|
|
@app.config.reload_classes_only_on_change != true || @app.reloaders.any?(&:updated?)
|
|
|
|
end
|
|
|
|
end
|
2012-03-10 15:30:15 -05:00
|
|
|
end if defined?(::Rails)
|
2012-01-25 16:32:51 -05:00
|
|
|
end
|