mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
abca42db3c
This reverts commita27d692656
. The reason for reverting is that this middleware has no effect. In Rails 5.0+, Sidekiq runs its jobs using the Rails reloader/executor API[1]. In Rails 5.0+, however, the ActiveRecord query cache registers its own hooks with the executor[2], and these hooks automatically enable the query cache for the duration of any work the executor performs[3]. As a result, the query cache is already on by default for any Sidekiq jobs run in Rails 5.0+, so it's not necessary to separately enable it in a middleware. [1]eca6acc0ce/lib/sidekiq/rails.rb (L33-L37)
[2]f8c00c1300/activerecord/lib/active_record/railtie.rb (L159-L163)
[3]f8c00c1300/activerecord/lib/active_record/query_cache.rb (L26-L41)
57 lines
No EOL
1.9 KiB
Ruby
57 lines
No EOL
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
module Sidekiq
|
|
class Rails < ::Rails::Engine
|
|
# 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
|
|
if ::Rails::VERSION::MAJOR < 5 && defined?(::ActiveRecord)
|
|
Sidekiq.server_middleware do |chain|
|
|
require 'sidekiq/middleware/server/active_record'
|
|
chain.add Sidekiq::Middleware::Server::ActiveRecord
|
|
end
|
|
end
|
|
end
|
|
|
|
config.after_initialize do
|
|
# 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
|
|
Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new
|
|
end
|
|
end
|
|
end
|
|
|
|
class Reloader
|
|
def initialize(app = ::Rails.application)
|
|
@app = app
|
|
end
|
|
|
|
def call
|
|
@app.reloader.wrap do
|
|
yield
|
|
end
|
|
end
|
|
|
|
def inspect
|
|
"#<Sidekiq::Rails::Reloader @app=#{@app.class.name}>"
|
|
end
|
|
end
|
|
end if defined?(::Rails)
|
|
end
|
|
|
|
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("**************************************************")
|
|
end |