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

add feature to deliver later #696

Merged
merged 6 commits into from
Jun 22, 2015
Merged

add feature to deliver later #696

merged 6 commits into from
Jun 22, 2015

Conversation

wendy0402
Copy link
Contributor

It is feature to use deliver_later method that exists since rails 4.2 for Action Mailer by using active job( the issue is raised here: #675).

If the test is not good enough please tell me, thanks

@arnvald
Copy link
Collaborator

arnvald commented Jun 13, 2015

Hi @wendy0402,

thanks a lot for your work!
I'm wondering if instead of using respond_to a few times, wouldn't it be better to just let user specify method responsible for sending emails? i.e.
user.email_delivery_method = :deliver_now

This could default to :deliver_now for rails 4.2+ and :deliver for older versions.

It has 2 advantages over current approach:

  • config name is more accurate (deliver_later_enabled does not fully explain that it's about email, and the word "enabled" does not really mean that it will be used.)
  • the code responsible for sending email is simpler - we just need to run mail.send(config.email_delivery_method) and not care if mailer responds to certain method or not

What's your opinion?

@wendy0402
Copy link
Contributor Author

Hi @arnvald ,
so do you mean they are the one who choose to use deliver_now, deliver, or deliver_later? that can be a good idea, just need to add more information in initializer about the condition, I will update it, thanks for the suggestion

@wendy0402
Copy link
Contributor Author

I just remember, how about other user that after update the gem, they need to update their initializer also. we should make default method for them right? if true, do you think it is nice to check based on the rails version?

@arnvald
Copy link
Collaborator

arnvald commented Jun 13, 2015

@wendy0402

yes, so the documentation for user in initializer should specify that 3 methods are available: deliver, deliver_now and deliver_later.
By default deliver or deliver_now should be set based on rails version - user shouldn't be forced to updating initializer, update should be only if they want to set deliver_later

@wendy0402
Copy link
Contributor Author

If you think there is better solutions for how to check rails version, please tell me, I'll update it, thanks!

@arnvald
Copy link
Collaborator

arnvald commented Jun 13, 2015

Yes, there's an easier approach. You can use Gem::Version class:

if Gem::Version.new("4.2.0") <= Gem::Version.new(Rails.version)
  :deliver_now
else
  :deliver
end

else
mail.deliver
end
mail.send("#{config.email_delivery_method}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can just use mail.send(config.email_delivery_method) here

@arnvald
Copy link
Collaborator

arnvald commented Jun 21, 2015

@wendy0402 sorry for late reply. I've just checked the code again, there's just one small fix and PR is ready to merge 👍 :shipit:

@wendy0402
Copy link
Contributor Author

no problem @arnvald , I guess it is ready now

arnvald added a commit that referenced this pull request Jun 22, 2015
add feature to deliver later
@arnvald arnvald merged commit 006fa67 into NoamB:master Jun 22, 2015
@arnvald
Copy link
Collaborator

arnvald commented Jun 22, 2015

Merged, thank you for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants