Ruby on Rails Wednesday, July 31, 2013

On Wednesday, July 31, 2013 5:21:56 AM UTC+1, Ruby-Forum.com User wrote:
> Hi everyone,
>
>
>
> I am having a problem with running rake tasks that involve threads.
>
> Everytime I run it, I get an uninitialized constant with one of my
>
> models (changes models occasionally) seems to be uninitialized.
>
>
>
> I have tried to fix this by adding config.threadsafe! in the
>
> application.rb. That did not work. So I tried to add
>
> Rails.application.eager.load! and that did not work. I have tried to put
>
> config.dependency_loading = true if $rails_rake_task but that does not
>
> work. I have tried config.threadsafe! unless $rails_rake_task but that
>
> did not work also.
>
>

Loading classes is inherently a thread unsafe task - you run into all sorts of race conditions. While rails has mechanisms for loading all code upfront (it does that in production by default), and this is one of the things that config.threadsafe! does. My recollection is that this disabled for rake tasks though - I don't recall the precise reasons though. If all else fails, you could use require_dependency to load all of the classes you'll need ahead of time.

Fred.

>
> I was wondering if anyone has come across this problem in which you are
>
> using threads in a rake file and you get the uninitialized constant on
>
> one of your models. Please help! I went through all the
>
> stackoverflow pages related to this and nothing works :( I have ruby
>
> 1.9.3-p429, rails 3.2.13, rubygem 2.0.6
>
>
>
> --
>
> Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2cd63ede-868f-4af5-b00a-99a77c72faf5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment