collectiveidea/delayed_job — pull request #672 by hqm42 (2014-06-19 09:06:07+00:00)
Title: allow mail rendering at delay time

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)