Skip to content

Allow configuration of ActionMailer queue name - #18587

Merged
rafaelfranca merged 1 commit into
rails:masterfrom
chrismcg:allow_deliver_later_queue_name_to_be_configured
Jun 3, 2015
Merged

Allow configuration of ActionMailer queue name#18587
rafaelfranca merged 1 commit into
rails:masterfrom
chrismcg:allow_deliver_later_queue_name_to_be_configured

Conversation

@chrismcg

Copy link
Copy Markdown
Contributor

Currently all mails sent with deliver_later are put on the mailers queue. This patch keeps that default but allows the queue name to be configured globally.

The motivation was trying to use https://github.com/chanks/que as the queuing backend. It's a good fit for a simple queue for a single dyno heroku app but by default only listens to one queue per application. As ActiveJob will use the default queue and ActionMailer the mailers queue jobs wouldn't get run.

The Que library might change to support more than one queue but in the meantime this will allow Rails to work with it. It will also be useful for users of other backends who might need to change where mails are queued.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats this for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For testing I could set the configuration separately from using it.

@senny

senny commented Jan 28, 2015

Copy link
Copy Markdown
Member

We need to configure the default AM queue as well in Queue Classic.

@mandrews

Copy link
Copy Markdown

+1

@cristianbica

Copy link
Copy Markdown
Member

I'm thinking of a cleaner approach. ActiveJob::Base accepts a Proc for the queue_as and that proc is executed when trying to enqueue the job so we can leverage that:

  class DeliveryJob < ActiveJob::Base # :nodoc:
    queue_as do
      ActionMailer::Base. deliver_later_queue_name || :mailers
    end
  end

what do you think @chrismcg?

@senny

senny commented Feb 12, 2015

Copy link
Copy Markdown
Member

@cristianbica I'm not sure I understand the benefit of that approach. Why not set :mailers as the default for that option? This way you can at least use introspection on deliver_later_queue_name to see where the jobs are going. Otherwise the default is hidden away.

@cristianbica

Copy link
Copy Markdown
Member

@senny yeah the || :mailers makes no sense here but my main suggesting was to keep defining the deliver_later_queue_name on ActionMailer base use use that in the DeliveryJob's queue_as. In this PR implementation the queue name is set in the MessageDelivery wrapper.

@senny

senny commented Feb 12, 2015

Copy link
Copy Markdown
Member

@cristianbica 👍 got it.

@chrismcg

Copy link
Copy Markdown
Contributor Author

@cristianbica sorry, I've only just seen your comment. I didn't know you could use a proc there so I'll have a look at it later in the week when I've a bit more time.

@jakegavin

Copy link
Copy Markdown
Contributor

+1
Just came across this while upgrading to 4.2. This would be nice to have. Thanks for working on it.

@chrismcg

Copy link
Copy Markdown
Contributor Author

@cristianbica finally got around to doing that change. I think it's clearer this way.

@cristianbica

Copy link
Copy Markdown
Member

Please squash your commits. Otherwise seems good to me.

@chrismcg

chrismcg commented Jun 2, 2015

Copy link
Copy Markdown
Contributor Author

Commits squashed, thanks!

@rafaelfranca
rafaelfranca merged commit f5a131a into rails:master Jun 3, 2015
rafaelfranca added a commit that referenced this pull request Jun 3, 2015
…e_to_be_configured

Allow configuration of ActionMailer queue name
rafaelfranca added a commit that referenced this pull request Jun 3, 2015
Also add a CHANGELOG entry for #18587

[ci skip]
@michaelsauter

Copy link
Copy Markdown

Is there a specific reason why this didn't make it into 4.2.4?

Judging by this PR, I thought it would be included since this has been merged on June 3, but 4.2.4 wasn't released until August 24.

@matthewd

Copy link
Copy Markdown
Member

@michaelsauter new features aren't backported to bugfix releases.

@michaelsauter

Copy link
Copy Markdown

@matthewd Ah okay, thanks. Though I think this almost counts as a bugfix ;)

@rafaelfranca rafaelfranca removed this from the 5.0.0 [temp] milestone Dec 30, 2015
@rossinkiwi

Copy link
Copy Markdown

I'm trying to set up separate mailer queues for transaction mail processing and bulk mail processing in my Rails 5.1.3 application. I was hoping to be able to designate the queue by setting the deliver_later_queue_name for each of my inherited ActionMailer's:

class ApplicationMailer < ActionMailer::Base
end

class UserMailer < ApplicationMailer  self.deliver_later_queue_name = 'mail'
  self.deliver_later_queue_name = 'mail'
  self.smtp_settings = {
    address: "smtp.sendgrid.net",
    port: 587,
    ...
}

class BulkMailer < ApplicationMailer
  self.deliver_later_queue_name = 'bulkmail'
  self.smtp_settings = {
    address: "email-smtp.us-west-2.amazonaws.com",
    port: 587,
    ...
  }

This works fine for the smtp_settings, but the deliver_later_queue_name appears to be a class variable? and so when I set it in the BulkMailer or UserMailer, it changes it for all the ActionMailer's.

Is there a way for me to set separate deliver_later_queue_name's for my BulkMailer and UserMailer?

@JamesLivengood

Copy link
Copy Markdown

Also curious about @rossinkiwi 's question

packagethief added a commit to packagethief/rails that referenced this pull request Feb 15, 2023
The `deliver_later_queue_name` is already configurable on ActionMailer::Base,
however the value is inherited by all subclasses. Use a class-inheritable
attribute instead, so that subclasses can override.

Refs:
- rails#18587 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.