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