取消过期缺陷邮件的发送(很有问题)!!!

This commit is contained in:
sw 2014-07-31 09:45:46 +08:00
parent 31e8ad98ae
commit 41d983e904
3 changed files with 41 additions and 33 deletions

View File

@ -0,0 +1,33 @@
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

View File

@ -104,7 +104,7 @@ class Mailer < ActionMailer::Base
message_id issue message_id issue
@author = issue.author @author = issue.author
@issue = issue @issue = issue
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
recipients = issue.recipients recipients = issue.recipients
cc = issue.watcher_recipients - recipients cc = issue.watcher_recipients - recipients
mail :to => recipients, mail :to => recipients,
@ -175,7 +175,7 @@ class Mailer < ActionMailer::Base
message_id issue message_id issue
@author = issue.author @author = issue.author
@issue = issue @issue = issue
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue) @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue.id)
recipients = issue.recipients recipients = issue.recipients
s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}") s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}")
mail :to => recipients, mail :to => recipients,
@ -582,34 +582,7 @@ class Mailer < ActionMailer::Base
end end
end end
#缺陷到期后发送邮件提示
#只监听已经提交的未到期的缺陷,已过期的缺陷默认已经发过邮件通知,不再提醒。
def mail_issue
threads = []
issues = Issue.where("done_ratio <> 100 and closed_on is null and due_date is not null and due_date > '#{Time.now.to_date}'")
issues.each do |issue|
thread = Thread.start 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)
#休眠一个小时。。。
sleep 3600
else
#发邮件
#puts issue.id.to_s
Mailer.issue_expire(issue).deliver
#Mailer.issue_add(issue).deliver
break
end
end
end
threads << thread
end
threads
end
private private

View File

@ -1,6 +1,8 @@
Mailer.mail_issue.each do |t| @threads = IssueOverdue.mail_issue
t.join #ii = 1
end #@threads.each do |t|
# t.join
#end
#Thread.new do #Thread.new do
# if Time.now == Time. # if Time.now == Time.