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