From 41d983e904ef11997ca9980ebfc8b722e7ee09f5 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 31 Jul 2014 09:45:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88=E8=BF=87=E6=9C=9F=E7=BC=BA?= =?UTF-8?q?=E9=99=B7=E9=82=AE=E4=BB=B6=E7=9A=84=E5=8F=91=E9=80=81(?= =?UTF-8?q?=E5=BE=88=E6=9C=89=E9=97=AE=E9=A2=98)=EF=BC=81=EF=BC=81?= =?UTF-8?q?=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/issue_overdue.rb | 33 +++++++++++++++++++++++++++++++++ app/models/mailer.rb | 33 +++------------------------------ config/initializers/task.rb | 8 +++++--- 3 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 app/models/issue_overdue.rb 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.