简体   繁体   中英

Rails 3 + Exception notifier: How do I use exception notifier for rake tasks?

So in the old plugin for Rails 2 there used to be a method called notifiable that I could use to surround whatever Rake task I needed to attach exception notifier to. However, when I try to run my rake task it gives me an undefined method error. I looked around and noticed someone else use the exception_notify method and tried replacing this:

task(:create_orders_for => :environment) do
  notifiable do
    ...
  end
end

with this:

exception_notify {:create_orders_for => :environment} do
  #notifiable do
    ...
end

But it doesn't work. Does anyone know what the Rails 3 version of this method is? I can't find it anywhere.

So this is what I eventually ended up doing. Works great.

  1. Add the middleware configuration to your environment/whatever_environment_you_want.rb file
  2. If you're testing in dev or test, you need to set the consider_all_requests_local to false
  3. Change your rake task to this:

     task(:create_orders_for => :environment) do begin ... rescue => e ExceptionNotifier::Notifier.exception_notification(Rails.env, e).deliver end 

    end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM