26

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?

Hallgeir Wilhelmsen
  • 1,014
  • 1
  • 10
  • 18

1 Answers1

48

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'
NobodysNightmare
  • 2,992
  • 2
  • 22
  • 33
mrstif
  • 2,736
  • 2
  • 27
  • 28
  • 8
    There will be a configuration option in Rails 5: https://github.com/rails/rails/commit/f5a131aaeaf0533e5f81461c2ad63474a865c19c#diff-97c5eb1c8630a41aec5c7b5453236d62 – skalee Oct 28 '15 at 16:39
  • 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 }`. – Rafał Cieślak Oct 31 '19 at 09:28