Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #9873 - generate unique alert mails for each user group member #2314

Closed
wants to merge 1 commit into from

Conversation

domcleal
Copy link
Contributor

To create distinct mails, new Mailer instances are required instead of using
the same one - else, the last message changes the previous ones. The recipient
list is now determined in the ReportImporter, and the MailNotification helps
create Mailers for each recipient.

The locale is also set correctly for each recipient this way, ensuring their
subject lines are now also translated.

@@ -30,6 +31,8 @@ def deliver
end

def group_mail(users, options)
ActiveSupport::Deprecation.warn '#group_mail is replaced by MailNotification#deliver with :users, this does not function properly'
Copy link
Member

Choose a reason for hiding this comment

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

Might be clearer to say something like :users in the options hash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed.

@stbenjam
Copy link
Member

It's nice to see someone more experienced in Rails touch my code 😄 It was useful to read through and see how you did things. Doing the locale in a block didn't occur to me.

One concern I do have, and it's kind of a big one, is Katello does some data processing in the mailers: https://github.com/Katello/katello/blob/master/app/mailers/katello/errata_mailer.rb#L26

Before, with the group_mail, the data was only gathered once, but now it's going be gathered each time for each user, that could be quite an overhead for dealing with Katello's bigger datasets.

Thoughts on that?

I would say for statistics it'd be fine to calculate it in the async action and pass to the mailer, but the errata summaries have up to 100 errata per mail, not sure I want to pass around such big data structures in foreman tasks many times, seems inefficient.

@domcleal
Copy link
Contributor Author

Before, with the group_mail, the data was only gathered once, but now it's going be gathered each time for each user, that could be quite an overhead for dealing with Katello's bigger datasets.

Thoughts on that?

None really, you need to figure out which makes most sense for your usage. Per-user data should be generated in the mailer so it's specific.

…up member

To create distinct mails, new Mailer instances are required instead of using
the same one - else, the last message changes the previous ones.  The recipient
list is now determined in the ReportImporter, and the MailNotification helps
create Mailers for each recipient.

The locale is also set correctly for each recipient this way, ensuring their
subject lines are now also translated.
@stbenjam
Copy link
Member

None really, you need to figure out which makes most sense for your usage. Per-user data should be generated in the mailer so it's specific.

Katello (and other plugins could as well) have data sets that are not user-specific, but need to be calculated.

For a dozen users subscribed to repo sync notification, now we're going to run 12x the SQL queries we would have otherwise, or have to send a big chunk of data through foreman tasks to the mailer. Maybe the latter is OK, but it'd be nicer if there was some solution to this in Foreman.

@domcleal
Copy link
Contributor Author

I think your problem lies with foreman-tasks and not Foreman, since Foreman doesn't restrict what can be passed into a mailer, which could be your whole dataset if calculating it outside.

@stbenjam
Copy link
Member

I guess it's fine then, tasks can call the mailer with the objects, just would've rather kept the logic all in one place

@domcleal
Copy link
Contributor Author

Might be nice, but I can't see how that's possible, mailers need to be unique or it just doesn't work reliably. I considered, and tried cloning them, but it wasn't the correct way to fix the bug.

mailer.constantize.send(method, *args, options.merge(:user => user)).deliver
end
else
mailer.constantize.send(method, *args).deliver
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be a bit more readable to return early rather than make the method an "if-else":

def deliver(options)
  return mailer.constantize.send(method, *args).deliver unless args.last.is_a?(Hash) && args.last.has_key?(:users)
  options = args.pop
  options.delete(:users).each do |user|
    mailer.constantize.send(method, *args, options.merge(:user => user)).deliver 
  end
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't say I find that any more readable because of the long line and conditional, sorry! It might only have to be refactored back later if the usual code path (the mail.constantize..) gets any more complex..

@dLobatog
Copy link
Member

Merged as 79ebdcd, thanks @domcleal!

@dLobatog dLobatog closed this May 21, 2015
ares added a commit to ares/foreman that referenced this pull request Aug 24, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 5, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 6, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 6, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 6, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 6, 2016
ares added a commit to ares/foreman that referenced this pull request Sep 6, 2016
tbrisker pushed a commit to tbrisker/foreman that referenced this pull request Sep 6, 2016
domcleal pushed a commit that referenced this pull request Sep 7, 2016
dhlavac pushed a commit to dhlavac/foreman that referenced this pull request Nov 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants