2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
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)
|
2016-07-01 12:31:08 -04:00
|
|
|
Sidekiq.logger.debug "Enabling Rails 5+ live code reloading, so hot!" unless app.config.cache_classes
|
2016-02-01 18:59:20 -05:00
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
2016-04-28 13:02:03 -04:00
|
|
|
@app.reloader.wrap do
|
|
|
|
yield
|
2016-02-01 18:59:20 -05:00
|
|
|
end
|
|
|
|
end
|
2016-04-28 13:38:46 -04:00
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<Sidekiq::Rails::Reloader @app=#{@app.class.name}>"
|
|
|
|
end
|
2016-02-01 18:59:20 -05:00
|
|
|
end
|
2012-03-10 15:30:15 -05:00
|
|
|
end if defined?(::Rails)
|
2012-01-25 16:32:51 -05:00
|
|
|
end
|