Rails 5:ActionMailer的“ deliver_later”从不交付生产 [英] Rails 5: ActionMailer's "deliver_later" never delivers in production

查看:87
本文介绍了Rails 5:ActionMailer的“ deliver_later”从不交付生产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a very basic mailer setup as follows to send out transactional mailers:

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

我正在用以下行进行测试:

Which I'm testing with this line:

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

我的问题是,当我使用.deliver或.deliver_now时,邮件会发送,但是当我使用Delivery_later异步委派它时,它会排队,但从不发送。输出为:

My issue is that when I use .deliver or .deliver_now, the mail sends, but when I delegate it asynchronously using deliver_later, it gets queued up but never sends. The output is:

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"

我知道当我使用liver_later时,ActionJob正在处理它,如文档

I know that ActionJob is handling it when I use deliver_later, as per the docs:


活动作业的默认行为是通过:async
适配器执行作业。因此,您现在可以使用delivery_later异步发送电子邮件
。 Active Job的默认适配器使用
进程内线程池运行作业。它非常适合开发/测试
的环境,因为它不需要任何
的外部基础架构,但由于在
重新启动时会挂起待处理的工作,因此不适合生产。如果需要持久性后端,则需要使用具有持久性后端(Sidekiq,Resque,
等)的
Active Job适配器。

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外部基础设施的情况下使用delivery_later?

At this point, I don't need a persistent backend and would be fine using the in-process thread pool. Is there any way for me to use deliver_later without bringing in the external infrastructure of Sidekiq + Redis?

推荐答案

异步适配器不会完成耙任务。

Async adapter won't work from a rake task.

尝试直接内联,或使用Delivery_now

Try inline instead, or use deliver_now

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


使用Rake任务中的异步队列(例如,使用.deliver_later发送电子邮件)通常不起作用,因为Rake可能会结束,从而导致进程内线程在处理任何/所有.deliver_later电子邮件之前,要删除的池。为避免此问题,请使用.deliver_now或在开发中运行持久队列。

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.

这篇关于Rails 5:ActionMailer的“ deliver_later”从不交付生产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆