我如何在Ruby on Rails的数组上应用睡眠功能 [英] How may i apply sleep functionality on array in Ruby on rails

查看:75
本文介绍了我如何在Ruby on Rails的数组上应用睡眠功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我使用过pluck的Rails项目中工作

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

所以我如何向更多emp发送电子邮件。

so how may i send email to more emp.

推荐答案

尝试以下代码

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

这篇关于我如何在Ruby on Rails的数组上应用睡眠功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆