bigpotato
bigpotato

Reputation: 27557

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.

Upvotes: 0

Views: 271

Answers (1)

bigpotato
bigpotato

Reputation: 27557

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

Upvotes: 1

Related Questions