Rails ActiveJob - What's the good way to handle exception in ActionMailer::DeliveryJob

 ̄綄美尐妖づ 提交于 2019-12-10 16:38:11

问题


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

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?

Best Regards.


回答1:


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


来源:https://stackoverflow.com/questions/33646358/rails-activejob-whats-the-good-way-to-handle-exception-in-actionmailerdeliv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!