Setting a default queue for ActionMailer deliver_later?
Asked Answered
T

1

27

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")

Is there a way to do this in a general way, for all ActionMailers? To set the default ActionMailer queue?

Tumble answered 30/1, 2015 at 22:48 Comment(0)
R
49

Before Rails 5

Looking through Rails' source code you can see that they already set the default queue name as 'mailers'.

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

Since Rails 5

Rails 5 allows you to set the default queue naming by simply configuring it.

E.g. add to you application.rb:

config.action_mailer.deliver_later_queue_name = 'default_mailer_queue'
Rattling answered 13/2, 2015 at 16:37 Comment(2)
There will be a configuration option in Rails 5: github.com/rails/rails/commit/…Dragster
It doesn't seem to support setting a different queues for different mailers unfortunately. I guess the best way then is to use a monkey patch: queue_as { mailer = self.arguments.first; mailer == "FooMailer" ? :foo : :bar }.Xeres

© 2022 - 2024 — McMap. All rights reserved.