消印でactionmailerを使ってユーザーにメールを送っています。これはコントローラーの私のコードです:
@users = User.where(some condition)
@product = Product.find_by_name(some name).first
for user in @users
UserMailer.new_product_arrival(user, @product, home_url).deliver
end
そしてこれは私のuser_mailer.rb
def new_product_arrival(user,product,home_url)
@from = Settings.mailer_from_address
@recipients = user.login
@sent_on = Time.now
@user = user
@product = product
@content_type = "text/html"
@home_url = home_url
end
問題は、10人を超えるユーザーがいる場合、for
ループのために非常に長い時間がかかることです。マルチスレッドまたはバックグラウンドジョブを使用してこれを処理できるかどうかを知る必要があります。バックグラウンドジョブを使用したくありませんが、マルチスレッドを使用して上記を実装する方法を教えてもらえますか。
私はルビー1.8.7とレール3.0.7を使用しています