diff options
author | Xavier Noria <fxn@hashref.com> | 2012-06-26 23:25:40 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2012-06-26 23:25:40 -0700 |
commit | 21f9f1c67f4159348f07f054a5eccf5ca5d9865a (patch) | |
tree | 21bec5590cb5f8ec741c35ba7ae100be6a42d075 /guides/source | |
parent | 4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22 (diff) | |
parent | 6a8591525717821594e4ba7f0199b9a402b063db (diff) | |
download | rails-21f9f1c67f4159348f07f054a5eccf5ca5d9865a.tar.gz rails-21f9f1c67f4159348f07f054a5eccf5ca5d9865a.tar.bz2 rails-21f9f1c67f4159348f07f054a5eccf5ca5d9865a.zip |
Merge pull request #6863 from bcardarella/asyn-actionmailer-guides
Guide update for Async ActionMailer
Diffstat (limited to 'guides/source')
-rw-r--r-- | guides/source/action_mailer_basics.textile | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/guides/source/action_mailer_basics.textile b/guides/source/action_mailer_basics.textile index ebe774fbef..7c61cc4a8d 100644 --- a/guides/source/action_mailer_basics.textile +++ b/guides/source/action_mailer_basics.textile @@ -457,6 +457,7 @@ The following configuration options are best made in one of the environment file |+delivery_method+|Defines a delivery method. Possible values are <tt>:smtp</tt> (default), <tt>:sendmail</tt>, <tt>:file</tt> and <tt>:test</tt>.| |+perform_deliveries+|Determines whether deliveries are actually carried out when the +deliver+ method is invoked on the Mail message. By default they are, but this can be turned off to help functional testing.| |+deliveries+|Keeps an array of all the emails sent out through the Action Mailer with delivery_method :test. Most useful for unit and functional testing.| +|+async+|Setting this flag will turn on asynchronous message sending, message rendering and delivery will be pushed to <tt>Rails.queue</tt> for processing.| h4. Example Action Mailer Configuration @@ -514,3 +515,33 @@ end </ruby> In the test we send the email and store the returned object in the +email+ variable. We then ensure that it was sent (the first assert), then, in the second batch of assertions, we ensure that the email does indeed contain what we expect. + +h3. Asynchronous + +You can turn on application-wide asynchronous message sending by adding to your <tt>config/application.rb</tt> file: + +<ruby> +config.action_mailer.async = true +</ruby> + +Alternatively you can turn on async within specific mailers: + +<ruby> +class WelcomeMailer < ActionMailer::Base + self.async = true +end +</ruby> + +h4. Custom Queues + +If you need a different queue than <tt>Rails.queue</tt> for your mailer you can override <tt>ActionMailer::Base#queue</tt>: + +<ruby> +class WelcomeMailer < ActionMailer::Base + def queue + MyQueue.new + end +end +</ruby> + +Your custom queue should expect a job that responds to <tt>#run</tt>. |