gpt4 book ai didi

ruby-on-rails - rails 5 : ActionMailer's "deliver_later" never delivers in production

转载 作者:行者123 更新时间:2023-12-02 07:20:06 24 4
gpt4 key购买 nike

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

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"

我知道 ActionJob 在我使用 Deliver_later 时正在处理它,根据 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.

关于ruby-on-rails - rails 5 : ActionMailer's "deliver_later" never delivers in production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48364051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com