简体   繁体   English

Rails 3 +异常通知程序:如何在rake任务中使用异常通知程序?

[英]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. 因此,在旧的Rails插件中,曾经有一种称为notifiable的方法,我可以用它来包围将异常通知程序附加到的Rake任务。 However, when I try to run my rake task it gives me an undefined method error. 但是,当我尝试运行rake任务时,它给了我一个未定义的方法错误。 I looked around and noticed someone else use the exception_notify method and tried replacing this: 我环顾四周,发现其他人使用exception_notify方法并尝试替换此方法:

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? 有谁知道该方法的Rails 3版本是什么? 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 将中间件配置添加到您的环境/whatever_environment_you_want.rb文件
  2. If you're testing in dev or test, you need to set the consider_all_requests_local to false 如果要在开发人员或测试中进行测试,则需要将think_all_requests_local设置为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 结束

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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