从调度到 Sidekiq 的 ActiveJob 调用时 ActionMailerrescue_from 失败
我使用 Postmark 发送电子邮件,并希望捕获 Postmark::InactiveRecipientError
,该错误目前刚刚出现在我的 Sidekiq 队列中的死作业中。我在 postmark-rails wiki 上找到了我认为正确的路线: https://github.com/wildbit/postmark-rails/wiki/Error-Handling
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout 'mailer'
rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
private
def postmark_client
::Postmark::ApiClient.new(Rails.application.credentials.postmark_api_token)
end
def reactivate_and_retry(error)
error.recipients.each do |recipient|
bounce = postmark_client.bounces(emailFilter: recipient).first
next unless bounce
postmark_client.activate_bounce(bounce[:id])
end
# Try again immediately
message.deliver
end
end
当我在开发中测试上述内容时,一切正常。我的 UserMailer
转到 Sidekiq,它会启动并正确激活隐藏的电子邮件,我可以通过邮戳界面看到所做的更改。然而,在生产中,我的工作失败了:
undefined method 'reactivate_and_retry' for class '#
我无法找到任何资源 - 这个 GitHub 问题似乎是一个类似的问题,但没有太多信息 - https://github.com/mperham/sidekiq/issues/4161
我正在使用 Rails 6.1.4.4 和 Sidekiq 6.4.0。
I use Postmark for sending email and was looking to capture Postmark::InactiveRecipientError
which currently just ends up in my dead jobs in my Sidekiq queue. I found on the postmark-rails wiki, what I thought would be the correct course: https://github.com/wildbit/postmark-rails/wiki/Error-Handling
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout 'mailer'
rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
private
def postmark_client
::Postmark::ApiClient.new(Rails.application.credentials.postmark_api_token)
end
def reactivate_and_retry(error)
error.recipients.each do |recipient|
bounce = postmark_client.bounces(emailFilter: recipient).first
next unless bounce
postmark_client.activate_bounce(bounce[:id])
end
# Try again immediately
message.deliver
end
end
When I test the above in development, everything works. My UserMailer
goes to Sidekiq which kicks off and correctly activates a suppressed email which I can see the change made via the Postmark interface. However, in production, my jobs are failing with:
undefined method 'reactivate_and_retry' for class '#<Class:UserMailer>'
I haven't been able to find any resources -- this GitHub Issue seems to be a similar problem but doesn't have much for information -- https://github.com/mperham/sidekiq/issues/4161
I am using Rails 6.1.4.4 and Sidekiq 6.4.0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也有同样的问题。好像没有人有这个问题。
问题是该作业调用
handle_exception_with_mailer_class
并且它没有mailer的实例,因此它尝试调用类级别的方法。如果您将其定义为类方法,那么它应该可以工作,或者使用 lambda/块。https://github.com/rails/rails/blob/cf82c9d7826aa36f2481114961af02dbf39896dd/actionmailer/lib/action_mailer/delivery_job.rb#L37
I am having the same problem. It seems like nobody has this problem.
The problem is that the job calls
handle_exception_with_mailer_class
and this doesn't have an instance of mailer so it tries to call a class level method. If you define it as a class method it should work though, or use a lambda/block.https://github.com/rails/rails/blob/cf82c9d7826aa36f2481114961af02dbf39896dd/actionmailer/lib/action_mailer/delivery_job.rb#L37