由于我在 Heroku 应用程序上将 newrelic_rpm gem 从 3.5.8.72 更新到 3.6.1.88,我注意到 newrelic 正在加载我的 rake 任务,这给了我一些奇怪的错误:
rake aborted!
undefined method `before_save' for #<Class:0x00000003d2f908>
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:90:in `<class:Session>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:79:in `<class:SessionStore>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:53:in `<module:ActiveRecord>'
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/session_store.rb:3:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/configuration.rb:138:in `session_store'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:273:in `block in default_middleware_stack'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:237:in `tap'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:237:in `default_middleware_stack'
/app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:469:in `app'
...
我知道问题肯定来自 newrelic_rpm,所以我想知道如何以某种方式在 rake 任务中禁用它。
我尝试使用https://newrelic.com/docs/ruby/forcing-the-ruby-agent-to-start设置 ENV var,但它也会禁用 webapp 的 newrelic。有没有办法为我的所有 rake 任务设置 ENV var,但只能在 rake 上而不是在网络服务器中?
提前非常感谢!