From 460ce532714444e186a60d49c9251b93909d4a58 Mon Sep 17 00:00:00 2001 From: Eugene Kenny Date: Mon, 11 May 2020 16:31:48 +0100 Subject: [PATCH] Define Reloader class before callback that uses it (#4561) If the application has already been loaded before this file is required, the `after_initialize` callback runs immediately, but the Reloader class isn't defined yet. Also remove a comment about `cache_classes` that has been irrelevant since 701e06224cebfeeb1f9c84e3abd9b96263defa46. --- lib/sidekiq/rails.rb | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/sidekiq/rails.rb b/lib/sidekiq/rails.rb index a1c10e53..5ac6b3dc 100644 --- a/lib/sidekiq/rails.rb +++ b/lib/sidekiq/rails.rb @@ -4,6 +4,22 @@ require "sidekiq/worker" module Sidekiq class Rails < ::Rails::Engine + class Reloader + def initialize(app = ::Rails.application) + @app = app + end + + def call + @app.reloader.wrap do + yield + end + end + + def inspect + "#" + end + end + # By including the Options module, we allow AJs to directly control sidekiq features # via the *sidekiq_options* class method and, for instance, not use AJ's retry system. # AJ retries don't show up in the Sidekiq UI Retries tab, save any error data, can't be @@ -23,8 +39,6 @@ module Sidekiq # 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. config.after_initialize do @@ -32,21 +46,5 @@ module Sidekiq Sidekiq.options[:reloader] = Sidekiq::Rails::Reloader.new end end - - class Reloader - def initialize(app = ::Rails.application) - @app = app - end - - def call - @app.reloader.wrap do - yield - end - end - - def inspect - "#" - end - end end end