socialforge/app/models/issue_overdue.rb

33 lines
1012 B
Ruby
Raw Normal View History

class IssueOverdue < ActiveRecord::Base
#缺陷到期后发送邮件提示
#只监听已经提交的未到期的缺陷,已过期的缺陷默认已经发过邮件通知,不再提醒。
def self.mail_issue
threads = []
issues = Issue.where("done_ratio <> 100 and closed_on is null and due_date is not null")
puts issues
issues.each do |issue|
thread = Thread.new do
while true
cur_issue = Issue.find issue.id
if cur_issue.done_ratio == 100 || cur_issue.closed_on != nil
break
end
if Time.now < Time.parse(cur_issue.due_date.to_s)
#休眠一个小时。。。
puts cur_issue.id.to_s
sleep 5
else
#发邮件
puts "11" + issue.id.to_s
#Mailer.issue_expire(issue).deliver
Mailer.issue_add(issue).deliver
break
end
end
end
threads << thread
end
puts threads
return threads
end
end