Rails ActiveJob-在ActionMailer :: DeliveryJob中处理异常的好方法是什么 [英] Rails ActiveJob - What's the good way to handle exception in ActionMailer::DeliveryJob

查看:230
本文介绍了Rails ActiveJob-在ActionMailer :: DeliveryJob中处理异常的好方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails项目中使用ActiveJob + Sidekiq进行任务处理.

I am using ActiveJob + Sidekiq in my Rails project for task processing.

我直接使用MyMailer.some.deliver_later发送邮件.它将自动创建一个ActionMailer::DeliveryJob任务并将其放入Sidekiq队列.

I send my mails directly using MyMailer.some.deliver_later. It will automatically creates a ActionMailer::DeliveryJob task and put it in the Sidekiq queue.

问题是,从那里处理异常有什么好处?

The question is, what's the good to handle exceptions from there?

最好的问候.

推荐答案

根据 http://edgeguides. rubyonrails.org/active_job_basics.html ,我认为好的方法是在初始化程序中为ActionMailer::DeliveryJob设置异常错误处理程序,例如:

According to http://edgeguides.rubyonrails.org/active_job_basics.html, I think the good way is to setup exception error handlers for ActionMailer::DeliveryJob in an initializer, somethinglike:

ActionMailer::DeliveryJob.rescue_from(Net::SMTPSyntaxError) do |exception|
  unless ['501 Command parsing failed'].include?(exception.message.strip)
    raise exception
  end
end

这篇关于Rails ActiveJob-在ActionMailer :: DeliveryJob中处理异常的好方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆