mails are now sent in the background
This commit is contained in:
22
app/helpers/mailer_helper.rb
Normal file
22
app/helpers/mailer_helper.rb
Normal file
@@ -0,0 +1,22 @@
|
||||
module MailerHelper
|
||||
def background_mailer(mails)
|
||||
Thread.new do
|
||||
begin
|
||||
mails.each do |mail|
|
||||
begin
|
||||
mail.deliver
|
||||
rescue => e
|
||||
Rails.logger.error "---"
|
||||
Rails.logger.error "WARNING: '#{mail.try(:subject)}' failed for user #{@user.name}, #{@user.email}"
|
||||
Rails.logger.error e.message
|
||||
Rails.logger.error "---"
|
||||
end
|
||||
end
|
||||
ensure
|
||||
# threads open their own DB connection
|
||||
ActiveRecord::Base.connection.close
|
||||
Rails.logger.flush
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user