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

查看:504
本文介绍了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天全站免登陆