我一直在試圖弄清楚如何使用delayed_job和rails 3發送延遲的郵件。我已經嘗試了幾乎所有可行的可能性組合,我可以想到 - 我可以讓郵件在後臺運行,但我無法讓郵件延遲發送到未來的時間。在DB中delayed_jobs表清除,日誌說「發」的任務,該任務的delayed_job處理器拿起&說無故障發送任務......但郵件可以是:Rails 3/delayed_job - 通緝:延遲郵件的基本示例
- 立即發送,或
- 根本沒有到達
如果我嘗試在未來發送。
如果任何人都可以提供未來發送郵件的rails 3 delayed_job的裸機示例,我會非常感激。我敢肯定,很多人都這麼做,所以我懷疑我錯過了一些明顯的東西。一(無數)的組合,我試過如下:
的delayed_job:2.1.2 導軌:3.0.3 的ActionMailer:3.0.3
控制器:
class TestmailerController < ApplicationController
def index
Testmailer.delay.test_mail
end
end
梅勒:
class Testmailer < ActionMailer::Base
def test_mail
mail(:to => '([email protected]', :from => '(removedforprivacy)@gmail.com', :subject => 'Testing Delayed Job', :content_type => 'text/plain').deliver
end
handle_asynchronously :test_mail, :run_at => Proc.new { 2.minutes.from_now }
end
config/environments/development.rb的相關郵件部分:
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "(removedforprivacy)",
:password => "(removedforprivacy)",
:authentication => "plain",
:enable_starttls_auto => true
}
工作命令:
rake jobs:work
你知道如何在沒有延遲的情況下完成這個任務嗎?我想要使用handle_async ...方法。我喜歡能夠在所有被調用的地方延遲一個方法,而不是改變所有的調用者。 – baash05 2013-02-22 00:18:52