【问题标题】:Rails DeliveryJob deprecation warning: How to upgrade to MailDeliveryJob?Rails DeliveryJob 弃用警告:如何升级到 MailDeliveryJob?
【发布时间】:2023-03-06 18:21:01
【问题描述】:

我有一个控制器操作将电子邮件的传递排入队列。我为该控制器操作编写了一个测试,并且在运行测试时收到了弃用警告:

弃用警告:使用 DeliveryJob 和 Parameterized::DeliveryJob 已弃用,将在 Rails 中删除 6.1。请改用 MailDeliveryJob。

控制器:

  def send_email
    SubscriptionMailer.with(user_id: @user.id).send_welcome_email.deliver_later
  end

订阅邮件者:

class SubscriptionMailer < ApplicationMailer
  helper :auxiliaries
  before_action { @user = User.find_by(id: params[:user_id]) }

  def send_welcome_email
    @base_email = find_base_email_or_raise("welcome_email")
    @subject = "#{@user.fname} #{@base_email.subject}"

    send_email(subject: @subject)
  end
end

测试:

  test "#send_email should enqueue SubscriptionMailer's #send_welcome_email" do
    assert_emails 1 do
      get send_email_admin_subscriptions_activation_path(
        @user.id,
      )
    end
  end

如何升级我的应用程序以消除警告?

我已经 read about 在不同的帖子中取消注释 new_framework_defaults_6_0.rb 中的一行,但这并没有解决问题。

【问题讨论】:

  • 尝试在application.rb: config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob" 中添加此行(如果您还没有)
  • @Deepesh 谢谢,这确实修复了警告消息。但这会以任何方式影响电子邮件的传递方式吗?我们的测试套件没有失败,但我仍然很好奇它可能有其他影响。

标签: ruby-on-rails email actionmailer deprecation-warning


【解决方案1】:

要修复弃用警告,请将此行添加到 application.rb:

config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"

来源: https://github.com/rails/rails/issues/37068#issuecomment-545531362

问:这是否会以任何方式影响电子邮件的传递方式?

方法上的参数发生了变化:

# DeliveryJob
def perform(mailer, mail_method, delivery_method, *args)

# MailDeliveryJob
def perform(mailer, mail_method, delivery_method, args:, params: nil)

因此,您可能必须在适用的情况下更改方法调用中的参数。

您可以在此 PR 上找到更多详细信息:https://github.com/rails/rails/pull/34591

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-28
    • 2015-02-16
    • 2019-03-05
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多