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

[WIP] Issue #4209 - Add deliver_later option in send_devise_notification #4224

Conversation

HexterCH
Copy link

@HexterCH HexterCH commented Jul 28, 2016

#4209

Add a class variable deliver_later_option and modify the method send_devise_notification

Now you can just add config.deliver_later_option = true in your config/initailizers/devise.rb, and devise mailer will use deliver_later to send every letter.

Hope to get some feedback. 😄

* Add private method devliery_method in models/authenticatable
* Modify send_devise_notification by use delivery_method
@HexterCH HexterCH changed the title Issue #4209 - Add deliver_later option in send_devise_notification [WIP] Issue #4209 - Add deliver_later option in send_devise_notification Jul 28, 2016
@HexterCH HexterCH changed the title [WIP] Issue #4209 - Add deliver_later option in send_devise_notification Issue #4209 - Add deliver_later option in send_devise_notification Jul 28, 2016
@@ -187,8 +191,9 @@ def devise_mailer
def send_devise_notification(notification, *args)
message = devise_mailer.send(notification, self, *args)
# Remove once we move to Rails 4.2+ only.

if message.respond_to?(:deliver_now)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this if now, right? 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

@HexterCH what do you think of this? I guess that's the only pending piece we have here.

Copy link
Author

Choose a reason for hiding this comment

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

@lucasmazza , but if remove this if, that meanings if user's environment don't support deliver_now or deliver_later will failed.

And really sorry about that I respond so lately. 😭

@lucasmazza
Copy link
Contributor

@HexterCH thanks for tackling this, can you please add a small test case that asserts that the email is enqueued when the config is on?

@@ -286,6 +286,10 @@ module Test
mattr_accessor :token_generator
@@token_generator = nil

# Store devise notification delivery method, default is deliver now
mattr_accessor :deliver_later_option
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add a new commenting section to the initializer template to document this for new apps.

@HexterCH
Copy link
Author

HexterCH commented Aug 17, 2016

Sure, I am working on it. 😄

@HexterCH HexterCH changed the title Issue #4209 - Add deliver_later option in send_devise_notification [WIP]Issue #4209 - Add deliver_later option in send_devise_notification Aug 28, 2016
@HexterCH HexterCH changed the title [WIP]Issue #4209 - Add deliver_later option in send_devise_notification [WIP] Issue #4209 - Add deliver_later option in send_devise_notification Aug 28, 2016
@HexterCH HexterCH force-pushed the add-deliver-later-in-send-devise-notification branch from 81e48fd to 5329b61 Compare August 28, 2016 18:40
@HexterCH
Copy link
Author

HexterCH commented Sep 8, 2016

I am stuck on this test, any relative test that I can reference ? 🆘

@brunowego
Copy link

@HexterCH exactly what I want! Waiting anxiously.

@tegon
Copy link
Member

tegon commented Nov 25, 2017

@HexterCH Thanks for your contribution, we appreciate it!
Sorry for the late response, but I think I can help you with that failing spec.

Your test failed in builds for rails 4.2 and mongoid, with the error ActiveJob::SerializationError: Unsupported argument type: User.
I did some debugging here, and the reason that it failed is: on rails 4.2, ActiveJob requires that any model passed to it should include the module GlobalID::Identification. Your build doesn't fail with active_record because the module is included by default.
Some references:

We can solve this issue by including the module in our User test class for mongoid:

# test/rails_app/app/mongoid/user.rb
require 'shared_user'

class User
  include Mongoid::Document
  include Shim
  include SharedUser
+ # Required for ActiveJob serialization. Reference: http://edgeguides.rubyonrails.org/active_job_basics.html#globalid
+ include GlobalID::Identification

@tegon
Copy link
Member

tegon commented Jan 12, 2018

I'm closing this since it has been here for a long time and probably will be too hard to rebase it.
If you find that this can still be relevant, feel free to open a new pull request with a similar implementation.

Thank you!

@tegon tegon closed this Jan 12, 2018
seanpdoyle added a commit to seanpdoyle/devise that referenced this pull request Jul 26, 2023
Re-opens [heartcombo#4224][]

By default, all `Devise::Models::Authenticatable`-initiated Action
Mailer deliveries are transmitted immediately (within the
request-response cycle).

Transmitting emails and interacting with any third-party services over
SMTP or HTTP risk service outages and other types of network-related
failures.

This commit adds support for deferring delivery to be done from an
Action Job background worker queue through the [deliver_later][] method.

```ruby
 # config/initializers/devise.rb
Devise.mailer_delivery_method = :deliver_later
```

[heartcombo#4224]: heartcombo#4224
[deliver_now]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
[deliver_later]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later
seanpdoyle added a commit to seanpdoyle/devise that referenced this pull request Jul 26, 2023
Re-opens [heartcombo#4224][]

By default, all `Devise::Models::Authenticatable`-initiated Action
Mailer deliveries are transmitted immediately (within the
request-response cycle).

Transmitting emails and interacting with any third-party services over
SMTP or HTTP risk service outages and other types of network-related
failures.

This commit adds support for deferring delivery to be done from an
Action Job background worker queue through the [deliver_later][] method.

```ruby
 # config/initializers/devise.rb
Devise.mailer_delivery_method = :deliver_later
```

[heartcombo#4224]: heartcombo#4224
[deliver_now]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
[deliver_later]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later
@seanpdoyle
Copy link

@HexterCH @tegon I've re-opened this unit of work as part of #5610.

seanpdoyle added a commit to seanpdoyle/devise that referenced this pull request Sep 15, 2023
Re-opens [heartcombo#4224][]

By default, all `Devise::Models::Authenticatable`-initiated Action
Mailer deliveries are transmitted immediately (within the
request-response cycle).

Transmitting emails and interacting with any third-party services over
SMTP or HTTP risk service outages and other types of network-related
failures.

This commit adds support for deferring delivery to be done from an
Action Job background worker queue through the [deliver_later][] method.

```ruby
 # config/initializers/devise.rb
Devise.mailer_delivery_method = :deliver_later
```

[heartcombo#4224]: heartcombo#4224
[deliver_now]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
[deliver_later]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later
seanpdoyle added a commit to seanpdoyle/devise that referenced this pull request Jan 10, 2024
Re-opens [heartcombo#4224][]

By default, all `Devise::Models::Authenticatable`-initiated Action
Mailer deliveries are transmitted immediately (within the
request-response cycle).

Transmitting emails and interacting with any third-party services over
SMTP or HTTP risk service outages and other types of network-related
failures.

This commit adds support for deferring delivery to be done from an
Action Job background worker queue through the [deliver_later][] method.

```ruby
 # config/initializers/devise.rb
Devise.mailer_delivery_method = :deliver_later
```

[heartcombo#4224]: heartcombo#4224
[deliver_now]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
[deliver_later]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later
seanpdoyle added a commit to seanpdoyle/devise that referenced this pull request May 9, 2024
Re-opens [heartcombo#4224][]

By default, all `Devise::Models::Authenticatable`-initiated Action
Mailer deliveries are transmitted immediately (within the
request-response cycle).

Transmitting emails and interacting with any third-party services over
SMTP or HTTP risk service outages and other types of network-related
failures.

This commit adds support for deferring delivery to be done from an
Action Job background worker queue through the [deliver_later][] method.

```ruby
 # config/initializers/devise.rb
Devise.mailer_delivery_method = :deliver_later
```

[heartcombo#4224]: heartcombo#4224
[deliver_now]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_now
[deliver_later]: https://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants