增加定时任务

This commit is contained in:
sw 2014-07-25 11:09:47 +08:00
parent ec41054008
commit 6d5f72326f
3 changed files with 61 additions and 0 deletions

View File

@ -165,6 +165,31 @@ class Mailer < ActionMailer::Base
:subject => l(:mail_subject_reminder, :count => issues.size, :days => days)
end
#缺陷到期邮件通知
def issue_expire issue
#@issues = issues
#s = l(:text_issue_expire,:issue => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}")
#puts s + "////" + issue.assigned_to.mail
#@issues_url = url_for(:controller => 'issues', :action => 'show',:id => issue.id)
#mail :to => issue.assigned_to.mail,
# :subject => s
issue_id = issue.project_index
redmine_headers 'Project' => issue.project.identifier,
'Issue-Id' => issue_id,
'Issue-Author' => issue.author.login
redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
message_id issue
@author = issue.author
@issue = issue
@issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
recipients = issue.recipients
cc = issue.watcher_recipients - recipients
mail :to => recipients,
:cc => cc,
:subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue_id}] (#{issue.status.name}) #{issue.subject}"
end
# Builds a Mail::Message object used to email users belonging to the added document's project.
#
# Example:
@ -541,6 +566,35 @@ class Mailer < ActionMailer::Base
end
end
#缺陷到期后发送邮件提示
def mail_issue
threads = []
issues = Issue.where("done_ratio <> 100 && closed_on is null && due_date is not null")
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
puts threads.count.to_s
threads
end
private
# Appends a Redmine header field (name is prepended with 'X-Redmine-')
@ -571,4 +625,6 @@ class Mailer < ActionMailer::Base
def mylogger
Rails.logger
end
end

View File

@ -0,0 +1,4 @@
#Mailer.mail_issue.each do |t|
# t.join
#end

View File

@ -1134,6 +1134,7 @@ zh:
text_zoom_in: 放大
text_zoom_out: 缩小
text_applied_project: "用户 %{id} 申请加入项目 %{project}"
text_issue_expire: "分配给您的任务%{issue}即将到期"
default_role_manager: 管理人员
default_role_developer: 开发人员