diff --git a/app/models/issue_overdue.rb b/app/models/issue_overdue.rb new file mode 100644 index 000000000..342790f55 --- /dev/null +++ b/app/models/issue_overdue.rb @@ -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 \ No newline at end of file diff --git a/app/models/mailer.rb b/app/models/mailer.rb index 156b6a8c5..f6c5e1a9e 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -104,7 +104,7 @@ class Mailer < ActionMailer::Base message_id issue @author = issue.author @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 cc = issue.watcher_recipients - recipients mail :to => recipients, @@ -175,7 +175,7 @@ class Mailer < ActionMailer::Base message_id issue @author = issue.author @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 s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}") mail :to => recipients, @@ -582,34 +582,7 @@ class Mailer < ActionMailer::Base 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 diff --git a/config/initializers/task.rb b/config/initializers/task.rb index 51c903355..62d1d78e5 100644 --- a/config/initializers/task.rb +++ b/config/initializers/task.rb @@ -1,6 +1,8 @@ -Mailer.mail_issue.each do |t| - t.join -end +@threads = IssueOverdue.mail_issue +#ii = 1 +#@threads.each do |t| +# t.join +#end #Thread.new do # if Time.now == Time.