2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2012-01-25 16:32:51 -05:00
|
|
|
module Sidekiq
|
|
|
|
class Rails < ::Rails::Engine
|
2016-09-30 18:27:54 -04:00
|
|
|
# We need to setup this up before any application configuration which might
|
|
|
|
# change Sidekiq middleware.
|
|
|
|
#
|
|
|
|
# This hook happens after `Rails::Application` is inherited within
|
|
|
|
# config/application.rb and before config is touched, usually within the
|
|
|
|
# class block. Definitely before config/environments/*.rb and
|
|
|
|
# config/initializers/*.rb.
|
|
|
|
config.before_configuration do
|
2018-01-11 15:00:30 -05:00
|
|
|
if defined?(::ActiveRecord)
|
2016-09-30 18:27:54 -04:00
|
|
|
Sidekiq.server_middleware do |chain|
|
2018-01-11 15:00:30 -05:00
|
|
|
if ::Rails::VERSION::MAJOR < 5
|
|
|
|
require 'sidekiq/middleware/server/active_record'
|
|
|
|
chain.add Sidekiq::Middleware::Server::ActiveRecord
|
|
|
|
end
|
|
|
|
|
|
|
|
require 'sidekiq/middleware/server/active_record_cache'
|
|
|
|
chain.add Sidekiq::Middleware::Server::ActiveRecordCache
|
2016-09-30 18:27:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config.after_initialize do
|
2016-12-12 12:39:12 -05:00
|
|
|
# This hook happens after all initializers are run, just before returning
|
|
|
|
# from config/environment.rb back to sidekiq/cli.rb.
|
|
|
|
# We have to add the reloader after initialize to see if cache_classes has
|
|
|
|
# been turned on.
|
|
|
|
#
|
|
|
|
# None of this matters on the client-side, only within the Sidekiq process itself.
|
|
|
|
#
|
|
|
|
Sidekiq.configure_server do |_|
|
|
|
|
if ::Rails::VERSION::MAJOR >= 5
|
2017-01-17 17:58:08 -05:00
|
|
|
Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
|
2016-09-30 18:27:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 18:59:20 -05:00
|
|
|
class Reloader
|
|
|
|
def initialize(app = ::Rails.application)
|
|
|
|
@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
|
2017-10-26 16:08:25 -04:00
|
|
|
|
|
|
|
if defined?(::Rails) && ::Rails::VERSION::MAJOR < 4
|
|
|
|
$stderr.puts("**************************************************")
|
|
|
|
$stderr.puts("⛔️ WARNING: Sidekiq server is no longer supported by Rails 3.2 - please ensure your server/workers are updated")
|
|
|
|
$stderr.puts("**************************************************")
|
2018-01-11 15:00:30 -05:00
|
|
|
end
|