small medium large xlarge

01 Aug 2012, 23:07
Will DelHagen (22 posts)

PDF: 164, PAPER: 146

Twitalytics is running fine on torquebox on my local machine. I’ve been through all of the steps to deploy to the vagrant box, and they are all completing successfully. However, when I deploy the application, for some reason it is not loading the analytics_util.rb file from the lib directory, which is causing an error:

01:00:54,505 ERROR [org.torquebox.messaging] (Thread-2 (HornetQ-client-global-threads-1339801924)) Unable to process inbound message: org.jruby.exceptions.RaiseException: (NameError) uninitialized constant Analytics::AnalyticsUtil
	at org.jruby.RubyModule.const_missing(org/jruby/ [jruby.jar:]
	at Module.const_missing(/opt/torquebox/jboss/standalone/tmp/vfs/deploymentcde565e6dade5e33/twitalytics.knob-7ddd9968a51a8669/vendor/bundle/jruby/1.8/gems/rake-	at [jruby.jar:]
	at (Anonymous).calc_positivity_followers_r(/opt/torquebox-2.1.0/jboss/standalone/tmp/vfs/deploymentcde565e6dade5e33/twitalytics.knob-7ddd9968a51a8669/app/models/analytics.rb:25)	at (Anonymous).refresh(/opt/torquebox-2.1.0/jboss/standalone/tmp/vfs/deploymentcde565e6dade5e33/twitalytics.knob-7ddd9968a51a8669/app/models/analytics.rb:14)	at AnalyticsProcessor.on_message(/opt/torquebox-2.1.0/jboss/standalone/tmp/vfs/deploymentcde565e6dade5e33/twitalytics.knob-7ddd9968a51a8669/app/processors/analytics_processor.rb:20)	at MessageProcessor.process!(/opt/torquebox/jruby/lib/ruby/gems/1.8/gems/torquebox-messaging-2.1.0-java/lib/torquebox/messaging/message_processor.rb:39)	at ProcessorWrapper.process!(/opt/torquebox/jruby/lib/ruby/gems/1.8/gems/torquebox-messaging-2.1.0-java/lib/torquebox/messaging/processor_wrapper.rb:32)	at [jruby.jar:]
	at [jruby.jar:]

Is there something about this deployment strategy or running in production that I have to do to get the classes in lib/ to autoload?

I tried replacing these lines in config/application.rb

    config.autoload_paths += %W(#{config.root}/lib)
    config.autoload_paths += %W(#{config.root}/lib/assets)
    config.autoload_paths += %W(#{config.root}/lib/tasks)
    config.autoload_paths += %W(#{config.root}/lib/workers)

with this line:

config.autoload_paths += Dir["#{config.root}/lib/**/"]

Bu that made no difference.

02 Aug 2012, 17:08
Joe Kutner (86 posts)

Hmm, that’s odd. I see you are using TorqueBox 2.1.0, and I recently noticed a post on the TB mailing list that may relate to this (deals with Rail env in background jobs). So it may be a TB bug or some kind of intentional change in the way it loads the env.

I’ll do some investigating with the newer version of TB, but in meantime you could try TB 2.0.3.

02 Aug 2012, 17:25
Will DelHagen (22 posts)

ok, I’ll try that. Is TB 2.0.3 more stable?

I think the problem here is that Rails disables autoloading when config.threadsafe! is true. I’ve tried adding these libs to config.eager_load_paths but it still didn’t work (though there may be other errors as well). One thing that tripped me up is that Rails “freezes” the eagerload_paths array at some point before environments/production.rb gets loaded, so you have to put the command in application.rb.

10 Jan 2013, 19:45
Rockford Yost (1 post)

Has anyone had any luck with this? I’m having the same issue and can’t seem to find a way around it.

10 Mar 2014, 13:38
Carter Shaw (1 post)

As far as i know, when running in threaded mode, anything in the libs needs to be specifically loaded. I use:

Dir.glob("#{Rails.root}/lib/*.rb") do |item| require item end

in production.rb