问题描述
您可以通过添加:queue作为可选参数来指定在ActionMailer中调用delivery_later时要使用的队列,例如:
You can specify which queue to use when calling deliver_later in an ActionMailer by adding :queue as optional argument, e.g.:
Notifier.welcome (User.first.id).deliver_later(queue: low)
有没有一种通用的方法,对于所有ActionMailer?要设置默认的ActionMailer队列?
Is there a way to do this in a general way, for all ActionMailers? To set the default ActionMailer queue?
推荐答案
在Rails 5之前
通过Rails的可以看到他们已经将默认队列名称设置为 邮件程序。
Before Rails 5
Looking through Rails' source code you can see that they already set the default queue name as 'mailers'.
不过,如果您想更改该默认名称,则始终可以通过以下方式覆盖它:在初始化程序或加载的lib文件中包含以下代码:
Still, if you want to change that default you can always override it by including the following code in an initialiser or loaded lib file:
class ActionMailer::DeliveryJob
queue_as :default_mailer_queue
end
自Rails 5起
Rails 5允许您通过简单配置来设置默认队列命名。
Since Rails 5
Rails 5 allows you to set the default queue naming by simply configuring it.
例如添加到您 application.rb
:
config.action_mailer.deliver_later_queue_name = 'default_mailer_queue'
这篇关于设置ActionMailer的默认队列delivery_later吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!