Rails 5:ActionMailer 的 "deliver_later" 从不在生产中交付

Rails 5: ActionMailer's "deliver_later" never delivers in production

我有一个非常基本的邮件设置,如下所示,用于发送交易邮件:

class PayoutMailer < ApplicationMailer
  default from: 'hello@groundworkai.com'

  def payout_success_email(email, payment_size, user_name)
    @payment_size = payment_size
    @user_name = user_name
    subject = 'Your Rewards Have Been Sent!'
    mail(to: email, from: 'hello@myservice.com', subject: subject)
  end
end

我正在用这条线测试:

PayoutMailer.payout_success_email('test@example.com',
                                          200000,
                                          'test name').deliver_later

我的问题是,当我使用 .deliver 或 .deliver_now 时,邮件会发送,但是当我使用 deliver_later 异步委托它时,它会排队但永远不会发送。输出是:

I, [2018-01-20T15:27:44.140104 #4]  INFO -- : [ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 265cb31a-dec4-4adb-866d-06e44645c53a) to Async(mailers) with arguments: "PayoutMailer", "payout_success_email", "deliver_now", "test@example.com", 200000, "test name"

我知道当我使用 deliver_later 时 ActionJob 正在处理它,根据 docs:

Active Job's default behavior is to execute jobs via the :async adapter. So, you can use deliver_later now to send emails asynchronously. Active Job's default adapter runs jobs with an in-process thread pool. It's well-suited for the development/test environments, since it doesn't require any external infrastructure, but it's a poor fit for production since it drops pending jobs on restart. If you need a persistent backend, you will need to use an Active Job adapter that has a persistent backend (Sidekiq, Resque, etc).

此时,我不需要持久性后端,使用进程内线程池就可以了。有什么方法可以让我在不引入 Sidekiq + Redis 的外部基础设施的情况下使用 deliver_later 吗?

异步适配器无法通过 rake 任务工作。

尝试内联,或使用 deliver_now

来自 http://edgeguides.rubyonrails.org/active_job_basics.html#job-execution

Using the asynchronous queue from a Rake task (for example, to send an email using .deliver_later) will generally not work because Rake will likely end, causing the in-process thread pool to be deleted, before any/all of the .deliver_later emails are processed. To avoid this problem, use .deliver_now or run a persistent queue in development.