delayed_job icon indicating copy to clipboard operation
delayed_job copied to clipboard

allow mail rendering at delay time

Open hqm42 opened this issue 10 years ago • 2 comments

The current solution to delayed mail delivery renders the mail template at delivery time:

Notifier.delay.signup(@user)

This can lead to problems, if your data that is accessed by the mail template changed between delay time and delivery time.

When you try to explicitly delay delivery forcing rendering you will get an error:

Notifier.signup(@user).delay.deliver
# Use MyMailer.delay.mailer_action(args) to delay sending of emails.

The new approach will serialize the mail message at delay time using Mail::Message.encoded and deserialize using the constructor:

Notifier.signup(@user).delay.deliver
# works like expected (render message -> delay -> execute job -> deliver)

The old approach:

Notifier.delay.signup(@user)
# still works (delay -> execute job -> render message -> deliver)

hqm42 avatar Jun 19 '14 09:06 hqm42