From 4a0470de42c2b2d5942040cd3693310d9fc33729 Mon Sep 17 00:00:00 2001 From: Mike Perham Date: Fri, 28 Dec 2018 10:16:50 -0800 Subject: [PATCH] Remove Rails <5 code/patches/hacks, bump! --- lib/sidekiq/cli.rb | 11 +------- lib/sidekiq/extensions/action_mailer.rb | 14 +--------- .../middleware/server/active_record.rb | 23 --------------- lib/sidekiq/rails.rb | 28 ++----------------- lib/sidekiq/version.rb | 2 +- lib/sidekiq/web.rb | 13 --------- 6 files changed, 5 insertions(+), 86 deletions(-) delete mode 100644 lib/sidekiq/middleware/server/active_record.rb diff --git a/lib/sidekiq/cli.rb b/lib/sidekiq/cli.rb index 9625b7d3..b614137d 100644 --- a/lib/sidekiq/cli.rb +++ b/lib/sidekiq/cli.rb @@ -233,17 +233,8 @@ module Sidekiq if File.directory?(options[:require]) require 'rails' - if ::Rails::VERSION::MAJOR < 4 + if ::Rails::VERSION::MAJOR < 5 raise "Sidekiq no longer supports this version of Rails" - elsif ::Rails::VERSION::MAJOR == 4 - # Painful contortions, see 1791 for discussion - # No autoloading, we want to force eager load for everything. - require File.expand_path("#{options[:require]}/config/application.rb") - ::Rails::Application.initializer "sidekiq.eager_load" do - ::Rails.application.config.eager_load = true - end - require 'sidekiq/rails' - require File.expand_path("#{options[:require]}/config/environment.rb") else require 'sidekiq/rails' require File.expand_path("#{options[:require]}/config/environment.rb") diff --git a/lib/sidekiq/extensions/action_mailer.rb b/lib/sidekiq/extensions/action_mailer.rb index b962e199..3d27d4d1 100644 --- a/lib/sidekiq/extensions/action_mailer.rb +++ b/lib/sidekiq/extensions/action_mailer.rb @@ -19,21 +19,9 @@ module Sidekiq # The email method can return nil, which causes ActionMailer to return # an undeliverable empty message. if msg - deliver(msg) - else - raise "#{target.name}##{method_name} returned an undeliverable mail object" - end - end - - private - - def deliver(msg) - if msg.respond_to?(:deliver_now) - # Rails 4.2/5.0 msg.deliver_now else - # Rails 3.2/4.0/4.1 - msg.deliver + raise "#{target.name}##{method_name} returned an undeliverable mail object" end end end diff --git a/lib/sidekiq/middleware/server/active_record.rb b/lib/sidekiq/middleware/server/active_record.rb deleted file mode 100644 index f6e7ca36..00000000 --- a/lib/sidekiq/middleware/server/active_record.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true -module Sidekiq - module Middleware - module Server - class ActiveRecord - - def initialize - # With Rails 5+ we must use the Reloader **always**. - # The reloader handles code loading and db connection management. - if defined?(::Rails) && ::Rails::VERSION::MAJOR >= 5 - raise ArgumentError, "Rails 5 no longer needs or uses the ActiveRecord middleware." - end - end - - def call(*args) - yield - ensure - ::ActiveRecord::Base.clear_active_connections! - end - end - end - end -end diff --git a/lib/sidekiq/rails.rb b/lib/sidekiq/rails.rb index 773ce99a..ff4f669e 100644 --- a/lib/sidekiq/rails.rb +++ b/lib/sidekiq/rails.rb @@ -2,22 +2,6 @@ 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. @@ -27,9 +11,7 @@ module Sidekiq # 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 + Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new end end @@ -48,11 +30,5 @@ module Sidekiq "#" 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 end diff --git a/lib/sidekiq/version.rb b/lib/sidekiq/version.rb index 283a1133..fdaa90bd 100644 --- a/lib/sidekiq/version.rb +++ b/lib/sidekiq/version.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true module Sidekiq - VERSION = "5.2.3" + VERSION = "6.0.0" end diff --git a/lib/sidekiq/web.rb b/lib/sidekiq/web.rb index 7fc34bc5..5c1bb286 100644 --- a/lib/sidekiq/web.rb +++ b/lib/sidekiq/web.rb @@ -198,16 +198,3 @@ module Sidekiq Sidekiq::WebAction.class_eval "def _render\n#{ERB.new(File.read(Web::LAYOUT)).src}\nend" end - -if defined?(::ActionDispatch::Request::Session) && - !::ActionDispatch::Request::Session.method_defined?(:each) - # mperham/sidekiq#2460 - # Rack apps can't reuse the Rails session store without - # this monkeypatch, fixed in Rails 5. - class ActionDispatch::Request::Session - def each(&block) - hash = self.to_hash - hash.each(&block) - end - end -end