2

Is there an environment variable I could leverage in my rails initializers to determine if a rake task is executing ? Like -- rake db:migrate db:seed

I have a bunch of initializers that could be skipped for most rake tasks:

  • Don't load spring (it's a jruby project)
  • Don't load the audit observer that breaks the migration

Update:

I'm probably going to regret this later -- but the following seems to work --

In my application.rb -- have added the following:

config.is_rake = (File.basename($0) == 'rake')

Then I am checking for the value later on

config.active_record.observers = :audit_observer unless config.is_rake

Elsewhere in my spring initializer

SPRING_CONTEXT = org.springframework.context.support.FileSystemXmlApplicationContext.new(SPRING_XML_CONFIG_FILES) unless Rails.application.config.is_rake

Based on answer found here

Community
  • 1
  • 1
  • 1
    i'm not sure what to do in stack overflow land -- i'm satisfied with my implementation -- do I answer this? delete it ? – stringaling Nov 09 '11 at 17:18
  • Leave it for someone to find later. – Chuck Vose Sep 11 '12 at 20:22
  • +1 We had a similar need. And, I think this config.is_rake will be a good start. We also have Spring and don't want it to start during rake tasks, but more specifically things like asset compilation or in rails console. – mrjabba Oct 20 '12 at 01:14

0 Answers0