use resque mailer to send mail background

This commit is contained in:
RickXing 2012-05-12 17:01:09 +08:00
parent 9e5c016847
commit 25b80767bd
5 changed files with 38 additions and 32 deletions

View file

@ -36,6 +36,7 @@ gem 'bootstrap-sass', "2.0.2"
gem "colored" gem "colored"
gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git" gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git"
gem 'modularity' gem 'modularity'
gem 'resque_mailer'
group :assets do group :assets do
gem "sass-rails", "3.2.3" gem "sass-rails", "3.2.3"

View file

@ -222,6 +222,9 @@ GEM
redis-namespace (~> 1.0.2) redis-namespace (~> 1.0.2)
sinatra (>= 0.9.2) sinatra (>= 0.9.2)
vegas (~> 0.1.2) vegas (~> 0.1.2)
resque_mailer (2.0.3)
actionmailer (>= 3.0.0)
resque (>= 1.2.3)
rspec (2.8.0) rspec (2.8.0)
rspec-core (~> 2.8.0) rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0) rspec-expectations (~> 2.8.0)
@ -348,6 +351,7 @@ DEPENDENCIES
rake rake
redcarpet (~> 2.1.1) redcarpet (~> 2.1.1)
resque (~> 1.20.0) resque (~> 1.20.0)
resque_mailer
rspec-rails rspec-rails
sass-rails (= 3.2.3) sass-rails (= 3.2.3)
seed-fu seed-fu

View file

@ -1,4 +1,5 @@
class Notify < ActionMailer::Base class Notify < ActionMailer::Base
include Resque::Mailer
add_template_helper ApplicationHelper add_template_helper ApplicationHelper
default_url_options[:host] = EMAIL_OPTS["host"] default_url_options[:host] = EMAIL_OPTS["host"]
@ -9,68 +10,68 @@ class Notify < ActionMailer::Base
def new_user_email(user, password) def new_user_email(user, password)
@user = user @user = user
@password = password @password = password
mail(:to => @user.email, :subject => "gitlab | Account was created for you") mail(:to => @user['email'], :subject => "gitlab | Account was created for you")
end end
def new_issue_email(issue) def new_issue_email(issue)
@user = issue.assignee @issue = Issue.find(issue['id'])
@project = issue.project @user = @issue.assignee
@issue = issue @project = @issue.project
mail(:to => @user.email, :subject => "gitlab | New Issue was created") mail(:to => @user.email, :subject => "gitlab | New Issue was created")
end end
def note_wall_email(user, note) def note_wall_email(user, note)
@user = user @user = user
@note = note @note = Note.find(note['id'])
@project = note.project @project = @note.project
mail(:to => @user.email, :subject => "gitlab | #{@note.project.name} ") mail(:to => @user['email'], :subject => "gitlab | #{@note.project.name} ")
end end
def note_commit_email(user, note) def note_commit_email(user, note)
@user = user @user = user
@note = note @note = Note.find(note['id'])
@project = note.project @project = @note.project
@commit = @note.target @commit = @note.target
mail(:to => @user.email, :subject => "gitlab | note for commit | #{@note.project.name} ") mail(:to => @user['email'], :subject => "gitlab | note for commit | #{@note.project.name} ")
end end
def note_merge_request_email(user, note) def note_merge_request_email(user, note)
@user = user @user = user
@note = note @note = Note.find(note['id'])
@project = note.project @project = @note.project
@merge_request = note.noteable @merge_request = @note.noteable
mail(:to => @user.email, :subject => "gitlab | note for merge request | #{@note.project.name} ") mail(:to => @user['email'], :subject => "gitlab | note for merge request | #{@note.project.name} ")
end end
def note_issue_email(user, note) def note_issue_email(user, note)
@user = user @user = user
@note = note @note = Note.find(note['id'])
@project = note.project @project = @note.project
@issue = note.noteable @issue = @note.noteable
mail(:to => @user.email, :subject => "gitlab | note for issue #{@issue.id} | #{@note.project.name} ") mail(:to => @user['email'], :subject => "gitlab | note for issue #{@issue.id} | #{@note.project.name} ")
end end
def new_merge_request_email(merge_request) def new_merge_request_email(merge_request)
@user = merge_request.assignee @merge_request = MergeRequest.find(merge_request['id'])
@merge_request = merge_request @user = @merge_request.assignee
@project = merge_request.project @project = @merge_request.project
mail(:to => @user.email, :subject => "gitlab | new merge request | #{@merge_request.title} ") mail(:to => @user.email, :subject => "gitlab | new merge request | #{@merge_request.title} ")
end end
def changed_merge_request_email(user, merge_request) def changed_merge_request_email(user, merge_request)
@user = user @user = user
@assignee_was ||= User.find(merge_request.assignee_id_was) @merge_request = MergeRequest(merge_request.id)
@merge_request = merge_request @assignee_was ||= User.find(@merge_request.assignee_id_was)
@project = merge_request.project @project = @merge_request.project
mail(:to => @user.email, :subject => "gitlab | merge request changed | #{@merge_request.title} ") mail(:to => @user['email'], :subject => "gitlab | merge request changed | #{@merge_request.title} ")
end end
def changed_issue_email(user, issue) def changed_issue_email(user, issue)
@issue = Issue.find(issue['id'])
@user = user @user = user
@assignee_was ||= User.find(issue.assignee_id_was) @assignee_was ||= User.find(@issue.assignee_id_was)
@issue = issue @project = @issue.project
@project = issue.project mail(:to => @user['email'], :subject => "gitlab | changed issue | #{@issue.title} ")
mail(:to => @user.email, :subject => "gitlab | changed issue | #{@issue.title} ")
end end
end end

View file

@ -4,7 +4,7 @@
%td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
%td{:align => "left", :style => "padding: 20px 0 0;"} %td{:align => "left", :style => "padding: 20px 0 0;"}
%h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "} %h2{:style => "color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "}
Hi #{@user.name}! Hi #{@user['name']}!
%p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "} %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 20px; font-size: 12px;font-family: Helvetica, Arial, sans-serif; "}
Administrator created account for you. Now you are a member of company gitlab application. Administrator created account for you. Now you are a member of company gitlab application.
%td{:style => "font-size: 1px; line-height: 1px;", :width => "21"} %td{:style => "font-size: 1px; line-height: 1px;", :width => "21"}
@ -13,7 +13,7 @@
%td{:style => "padding: 15px 0 15px;", :valign => "top"} %td{:style => "padding: 15px 0 15px;", :valign => "top"}
%p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "} %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "}
login.......................................... login..........................................
%code= @user.email %code= @user['email']
%p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "} %p{:style => "color:#767676; font-weight: normal; margin: 0; padding: 0; line-height: 28px; font-size: 16px;font-family: Helvetica, Arial, sans-serif; "}
password.................................. password..................................
%code= @password %code= @password

View file

@ -1,2 +1,2 @@
mkdir -p tmp/pids mkdir -p tmp/pids
bundle exec rake environment resque:work QUEUE=post_receive RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid BACKGROUND=yes bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid BACKGROUND=yes