问题
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