寄信的工作是最必要丟背景的。在 web 前端使用的過程中,若要等待 server 產生 email 內容、和 smtp 連線、然後再把信送出去,這樣的過程肯定讓使用品質大大扣分…
因此 gem “resque_mailer” 將 resque 的 enqueue 和 perform 實作到 ActionMailer::Base 中
即原本的 deliver 應該是要根據 app 的 mailer 設定 (smtp或sendmail等) 把信送出
bundle resqie_mailer 後, deliver 的結果則變成送到 mq 上 (透過 Resque.enqueue)
安裝
1 2 |
|
設定
1 2 3 4 5 6 7 |
|
使用
1 2 3 4 5 6 7 |
|
寄信 (送到 mq)
1
|
|
寄信 (直接寄出不送 mq)
1
|
|
這裡要注意!!!!! 因為 resque 會將參數內容送到 mq 上, 而 redis 無法處理 number, string, array, hash 以外的變數, 所以在定義 mailer action 時, 參數務必限制在上述這些變數類型的範圍內
worker 的執行
一般 mailer 的 worker 建議獨立一條 queue 執行, 效率會比較好 :p
1
|
|
resque_mailer 簡單, 但仍是 background job
因此測試還是要多多寫 XD