How may i apply sleep functionality on array in Ruby on rails

微笑、不失礼 提交于 2019-12-12 03:27:44

问题


I am working on a project in rails where i have used pluck

 @employees = Employee.where.not("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')).pluck(:email)
 
 mail(to: @employees, subject: 'Birthday Invitation')
 
 when i am sending email using Whenever gems,email is not going.I am getting Rake aborted error

so how may i send email to more emp.


回答1:


Try below code

mailer

def birthday_email
  date = Date.today 
    @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')).where("age > 21")
    @employees.find_in_batches(batch_size: 20) do |group|
      group.each { |emp| mail(to: emp.email, subject: 'Birthday Wishes'); sleep 3;}
      sleep 5
    end

end


来源:https://stackoverflow.com/questions/42873678/how-may-i-apply-sleep-functionality-on-array-in-ruby-on-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!