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

Problems with class loading in Rails production (like) environments #15

Closed
maxigs opened this issue Jan 23, 2014 · 10 comments
Closed

Problems with class loading in Rails production (like) environments #15

maxigs opened this issue Jan 23, 2014 · 10 comments

Comments

@maxigs
Copy link

maxigs commented Jan 23, 2014

Hi,

there was a little issue with class loading (when processes/workers/threads are restarted i guess) that sometimes the workers did not load the rails environment properly.

Some errors like "circular dependency" or that methods on classes/objects are not found that should obviously be there.
It only happens in a environment where classes are cached (rails production or when otherwise activated).

The fix is to make sure the eager-loading the environment is manually triggered (which is deactivated by default for rake tasks).

Just add this line:

::Rails.application.eager_load!

Before doing anything else in the sneakers:run rake task and it works fine (did so far here).

@jondot
Copy link
Owner

jondot commented Jan 30, 2014

Thanks! yes, this is a symptom of a threaded context in ruby. I myself often try to eager load things as much as possible.
Will add to the Wiki - thank you!

update: https://github.com/jondot/sneakers/wiki/Eager-loading

@jondot jondot closed this as completed Jan 30, 2014
@abevoelker
Copy link
Contributor

To help other people find this, the full error message looks like this:

2014-04-14T00:24:26Z p-26612 t-owi3y51f8 ERROR: Circular dependency detected while autoloading constant Foo

@jondot
Copy link
Owner

jondot commented Apr 14, 2014

@abevoelker thanks!, I will also add your note to the Wiki page

@drewnichols
Copy link

I'm curious why this isn't built into sneakers:run rake task provided by the sneakers gem?

@sheerun
Copy link
Contributor

sheerun commented Mar 19, 2015

+1 for this being built into sneakers. It caused problems with our production. Could you reopen?

@rud
Copy link
Contributor

rud commented Mar 20, 2015

@sheerun: probably easiest to re-open as a pull-request. Just a thought :)

@nerikj
Copy link

nerikj commented Jul 22, 2015

Where did you add this line of code? In your own Rake task executing the sneakers:run task or in Rakefile?

I get "LoadError: No such file to load -- application_controller" all the time.

@drewnichols
Copy link

I created a lib/tasks/sneakers.rake to call this and then run the requested rake task

@nerikj
Copy link

nerikj commented Jul 23, 2015

Me too. Had to let the task depend on environment to not get the LoadError though. Don't know if this is correct but I'll try it out anyway.

task run2: :environment do
  ::Rails.application.eager_load!
  Rake::Task['sneakers:run'].invoke
end

@n3bulous
Copy link

n3bulous commented Feb 1, 2017

Just in case anyone lands here and wonders if it was added to the default rake task, it was on 2015.04.01: 4f07a83

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

8 participants