Orbit/app/jobs/email_cron.rb

42 lines
727 B
Ruby
Raw Normal View History

class EmailCron
@queue = :mail
def self.perform
@datas = MailCron.where(:mail_sentdate.lte => Time.now)
@datas.each do |mail_data|
@mail_j = 0
@read_mails = Array.new
@mails = mail_data.mail_to.split(",")
@mails.each do |send_mail|
@read_mails << send_mail
@mail_j += 1
if 0 == @mail_j % 30
MailCronMailer.cron_mail( mail_data.id, @read_mails.join(',') ).deliver
@read_mails = Array.new
sleep 10
end
end
if !@read_mails.join(',').blank?
MailCronMailer.cron_mail( mail_data.id, @read_mails.join(',') ).deliver
@read_mails = Array.new
sleep 10
end
end
end
end