Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

que in rails should enable eager_loading #184

Closed
joevandyk opened this issue Feb 10, 2017 · 2 comments
Closed

que in rails should enable eager_loading #184

joevandyk opened this issue Feb 10, 2017 · 2 comments

Comments

@joevandyk
Copy link
Contributor

joevandyk commented Feb 10, 2017

from sidekiq faq;

Rails has two features which are relevant here: eager loading and autoloading. Autoloading is only active in development mode and is not thread-safe so Sidekiq disables it and uses eager loading only. Eager loading loads your code only once when starting the server - it does not reload your code between jobs. If you have code located outside of the standard Rails directories (e.g. app/models, app/controllers, etc), Sidekiq will not see it unless you add the path to eager_load_paths in your Rails application configuration...

https://github.com/mperham/sidekiq/blob/efadb9ac69f57d07df51645939a01ee05b87d905/lib/sidekiq/cli.rb#L238-L242

@timdiggins
Copy link

Just FYI @joevandyk @chanks recommend this is closed, as time has passed and Sidekiq no longer does this AFAICT for rails 5+. (see below for rationale).

Sidekiq FAQ now

https://github.com/mperham/sidekiq/wiki/FAQ#why-doesnt-sidekiq-autoload-my-rails-application-code

Why doesn't Sidekiq autoload my Rails application code?
Sidekiq 4.2.0+ will reload code in Rails 5+ when running in development.

Sidekiq code now

There's an explicit pathway in the code for "# Rails 5+ && development mode, use Reloader".

        if ::Rails::VERSION::MAJOR < 4
          require 'sidekiq/rails'
          require File.expand_path("#{options[:require]}/config/environment.rb")
          ::Rails.application.eager_load!
        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
          # Rails 5+ && development mode, use Reloader
          require 'sidekiq/rails'
          require File.expand_path("#{options[:require]}/config/environment.rb")
        end

So I think this force eager-loading is only for pre v5 (maybe the intention was for 4.2.0+, but the code says 5+).

@chanks
Copy link
Collaborator

chanks commented Apr 15, 2018

Cleaning up old issues. Yeah, I'm going to close this since it's old, people aren't really complaining about it and I don't think we should add any more Rails-specific logic unless it's really necessary (it's very difficult to test well).

@chanks chanks closed this as completed Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants