Why does rake behave differently in production

35 views
Skip to first unread message

Tyler DeWitt

unread,
Aug 7, 2015, 4:38:17 PM8/7/15
to Ruby on Rails: Talk
Hello,

I use RabbitMQ to transfer information from one component to another within my system. I have written a rake task which sets up the RabbitMQ client (the Bunny gem), then sets up a blocking listener so that I can process incoming messages.  When I run this rake task, I use the :environment task to load the rails app (the rake task relies on several models and service objects). 

When I deployed my system to production, I noticed that my Rabbit task was not working as expected. Digging into the log, I found that the service objects and models were not being loaded by rake. This was strange, since I called :environment.  Looking further into it, I've been informed that this is the expected behavior, that rake does not preload the rails environment in production.

I'm guessing I'm doing something wrong. Should I not be using rake to set up these listeners? If rake is acceptable, is there a way to test the load path so I see these errors before production?  Is :environment only designed to be used in development?

Thanks,
Tyler

Matt Jones

unread,
Aug 20, 2015, 6:55:29 PM8/20/15
to Ruby on Rails: Talk
:environment should work everywhere - I've been using it in production rake tasks for years. Can you be more specific about how the task was "not working as expected"? If it failed to start, what was the error message? Try running it with `--trace` to capture the stack trace when it fails.

--Matt Jones 

tyler.scott.dewitt

unread,
Aug 21, 2015, 10:31:04 AM8/21/15
to rubyonra...@googlegroups.com
Hi Matt,

I was having issues where I was getting undefined methods on my service objects, as if the service object was not being loaded into memory.   I’ve tried to recreate the problem, but I can not. It appears this is non reproducible and I must have had a stale environment or some other weird anomaly. 

Thanks for checking in,
Tyler
--
You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-talk/IJxjpV5gbCA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f7ecb2ee-9fa5-45c1-a486-69db67c9ba26%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages