Commit 71bd9568669d18bc04c551a603a04af2ea99328c

Authored by Dmitriy Zaporozhets
1 parent c7bb3a1f

email via sidekiq. start and stop rake tasks

@@ -84,7 +84,6 @@ gem "draper", "~> 0.18.0" @@ -84,7 +84,6 @@ gem "draper", "~> 0.18.0"
84 gem 'slim' 84 gem 'slim'
85 gem 'sinatra', :require => nil 85 gem 'sinatra', :require => nil
86 gem 'sidekiq', '2.6.4' 86 gem 'sidekiq', '2.6.4'
87 -gem 'sidekiq_mailer'  
88 87
89 # HTTP requests 88 # HTTP requests
90 gem "httparty" 89 gem "httparty"
@@ -407,10 +407,6 @@ GEM @@ -407,10 +407,6 @@ GEM
407 multi_json (~> 1) 407 multi_json (~> 1)
408 redis (~> 3) 408 redis (~> 3)
409 redis-namespace 409 redis-namespace
410 - sidekiq_mailer (0.0.4)  
411 - actionmailer (~> 3.0)  
412 - activesupport (~> 3.0)  
413 - sidekiq (~> 2.3)  
414 simplecov (0.7.1) 410 simplecov (0.7.1)
415 multi_json (~> 1.0) 411 multi_json (~> 1.0)
416 simplecov-html (~> 0.7.1) 412 simplecov-html (~> 0.7.1)
@@ -543,7 +539,6 @@ DEPENDENCIES @@ -543,7 +539,6 @@ DEPENDENCIES
543 settingslogic 539 settingslogic
544 shoulda-matchers (= 1.3.0) 540 shoulda-matchers (= 1.3.0)
545 sidekiq (= 2.6.4) 541 sidekiq (= 2.6.4)
546 - sidekiq_mailer  
547 simplecov 542 simplecov
548 sinatra 543 sinatra
549 six 544 six
1 web: bundle exec rails s -p $PORT 1 web: bundle exec rails s -p $PORT
2 -worker: bundle exec sidekiq -q post_receive,mailer,system_hook,common 2 +worker: bundle exec rake sidekiq:start
app/mailers/notify.rb
1 class Notify < ActionMailer::Base 1 class Notify < ActionMailer::Base
2 - include Sidekiq::Mailer 2 +
3 add_template_helper ApplicationHelper 3 add_template_helper ApplicationHelper
4 add_template_helper GitlabMarkdownHelper 4 add_template_helper GitlabMarkdownHelper
5 5
app/models/project.rb
@@ -251,7 +251,7 @@ class Project &lt; ActiveRecord::Base @@ -251,7 +251,7 @@ class Project &lt; ActiveRecord::Base
251 251
252 def send_move_instructions 252 def send_move_instructions
253 self.users_projects.each do |member| 253 self.users_projects.each do |member|
254 - Notify.project_was_moved_email(member.id).deliver 254 + Notify.delay.project_was_moved_email(member.id)
255 end 255 end
256 end 256 end
257 257
app/observers/issue_observer.rb
@@ -3,7 +3,7 @@ class IssueObserver &lt; ActiveRecord::Observer @@ -3,7 +3,7 @@ class IssueObserver &lt; ActiveRecord::Observer
3 3
4 def after_create(issue) 4 def after_create(issue)
5 if issue.assignee && issue.assignee != current_user 5 if issue.assignee && issue.assignee != current_user
6 - Notify.new_issue_email(issue.id).deliver 6 + Notify.delay.new_issue_email(issue.id)
7 end 7 end
8 end 8 end
9 9
@@ -16,7 +16,7 @@ class IssueObserver &lt; ActiveRecord::Observer @@ -16,7 +16,7 @@ class IssueObserver &lt; ActiveRecord::Observer
16 if status 16 if status
17 Note.create_status_change_note(issue, current_user, status) 17 Note.create_status_change_note(issue, current_user, status)
18 [issue.author, issue.assignee].compact.each do |recipient| 18 [issue.author, issue.assignee].compact.each do |recipient|
19 - Notify.issue_status_changed_email(recipient.id, issue.id, status, current_user.id).deliver 19 + Notify.delay.issue_status_changed_email(recipient.id, issue.id, status, current_user.id)
20 end 20 end
21 end 21 end
22 end 22 end
@@ -27,7 +27,7 @@ class IssueObserver &lt; ActiveRecord::Observer @@ -27,7 +27,7 @@ class IssueObserver &lt; ActiveRecord::Observer
27 recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id } 27 recipient_ids = [issue.assignee_id, issue.assignee_id_was].keep_if {|id| id && id != current_user.id }
28 28
29 recipient_ids.each do |recipient_id| 29 recipient_ids.each do |recipient_id|
30 - Notify.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was).deliver 30 + Notify.delay.reassigned_issue_email(recipient_id, issue.id, issue.assignee_id_was)
31 end 31 end
32 end 32 end
33 end 33 end
app/observers/merge_request_observer.rb
@@ -3,7 +3,7 @@ class MergeRequestObserver &lt; ActiveRecord::Observer @@ -3,7 +3,7 @@ class MergeRequestObserver &lt; ActiveRecord::Observer
3 3
4 def after_create(merge_request) 4 def after_create(merge_request)
5 if merge_request.assignee && merge_request.assignee != current_user 5 if merge_request.assignee && merge_request.assignee != current_user
6 - Notify.new_merge_request_email(merge_request.id).deliver 6 + Notify.delay.new_merge_request_email(merge_request.id)
7 end 7 end
8 end 8 end
9 9
@@ -25,7 +25,7 @@ class MergeRequestObserver &lt; ActiveRecord::Observer @@ -25,7 +25,7 @@ class MergeRequestObserver &lt; ActiveRecord::Observer
25 recipients_ids.delete current_user.id 25 recipients_ids.delete current_user.id
26 26
27 recipients_ids.each do |recipient_id| 27 recipients_ids.each do |recipient_id|
28 - Notify.reassigned_merge_request_email(recipient_id, merge_request.id, merge_request.assignee_id_was).deliver 28 + Notify.delay.reassigned_merge_request_email(recipient_id, merge_request.id, merge_request.assignee_id_was)
29 end 29 end
30 end 30 end
31 end 31 end
app/observers/note_observer.rb
@@ -11,7 +11,7 @@ class NoteObserver &lt; ActiveRecord::Observer @@ -11,7 +11,7 @@ class NoteObserver &lt; ActiveRecord::Observer
11 notify_team(note) 11 notify_team(note)
12 elsif note.notify_author 12 elsif note.notify_author
13 # Notify only author of resource 13 # Notify only author of resource
14 - Notify.note_commit_email(note.commit_author.id, note.id).deliver 14 + Notify.delay.note_commit_email(note.commit_author.id, note.id)
15 else 15 else
16 # Otherwise ignore it 16 # Otherwise ignore it
17 nil 17 nil
@@ -26,7 +26,7 @@ class NoteObserver &lt; ActiveRecord::Observer @@ -26,7 +26,7 @@ class NoteObserver &lt; ActiveRecord::Observer
26 26
27 if Notify.respond_to? notify_method 27 if Notify.respond_to? notify_method
28 team_without_note_author(note).map do |u| 28 team_without_note_author(note).map do |u|
29 - Notify.send(notify_method, u.id, note.id).deliver 29 + Notify.delay.send(notify_method, u.id, note.id)
30 end 30 end
31 end 31 end
32 end 32 end
app/observers/user_observer.rb
@@ -2,7 +2,7 @@ class UserObserver &lt; ActiveRecord::Observer @@ -2,7 +2,7 @@ class UserObserver &lt; ActiveRecord::Observer
2 def after_create(user) 2 def after_create(user)
3 log_info("User \"#{user.name}\" (#{user.email}) was created") 3 log_info("User \"#{user.name}\" (#{user.email}) was created")
4 4
5 - Notify.new_user_email(user.id, user.password).deliver 5 + Notify.delay.new_user_email(user.id, user.password)
6 end 6 end
7 7
8 def after_destroy user 8 def after_destroy user
app/observers/users_project_observer.rb
1 class UsersProjectObserver < ActiveRecord::Observer 1 class UsersProjectObserver < ActiveRecord::Observer
2 def after_commit(users_project) 2 def after_commit(users_project)
3 return if users_project.destroyed? 3 return if users_project.destroyed?
4 - Notify.project_access_granted_email(users_project.id).deliver 4 + Notify.delay.project_access_granted_email(users_project.id)
5 end 5 end
6 6
7 def after_create(users_project) 7 def after_create(users_project)
config/routes.rb
@@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do @@ -12,7 +12,7 @@ Gitlab::Application.routes.draw do
12 12
13 constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? } 13 constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
14 constraints constraint do 14 constraints constraint do
15 - mount Sidekiq::Web, at: "/admin/workers", as: :sidekiq 15 + mount Sidekiq::Web, at: "/admin/sidekiq", as: :sidekiq
16 end 16 end
17 17
18 # Enable Grack support 18 # Enable Grack support
lib/tasks/resque.rake
@@ -1,23 +0,0 @@ @@ -1,23 +0,0 @@
1 -require 'resque/tasks'  
2 -  
3 -namespace :resque do  
4 - task setup: :environment do  
5 - #Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }  
6 - end  
7 -  
8 - desc "Resque | kill all workers (using -QUIT), god will take care of them"  
9 - task :stop_workers => :environment do  
10 - #pids = Array.new  
11 -  
12 - #Resque.workers.each do |worker|  
13 - #pids << worker.to_s.split(/:/).second  
14 - #end  
15 -  
16 - #if pids.size > 0  
17 - #system("kill -QUIT #{pids.join(' ')}")  
18 - #end  
19 - end  
20 -end  
21 -  
22 -desc "Alias for resque:work (To run workers on Heroku)"  
23 -task "jobs:work" => "resque:work"  
lib/tasks/sidekiq.rake 0 → 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +namespace :sidekiq do
  2 + desc "GITLAB | Stop sidekiq"
  3 + task :stop do
  4 + run "bundle exec sidekiqctl stop #{pidfile}"
  5 + end
  6 +
  7 + desc "GITLAB | Start sidekiq"
  8 + task :start do
  9 + run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{rails_env} -P #{pidfile} >> #{root_path}/log/sidekiq.log 2>&1 &"
  10 + end
  11 +
  12 + def root_path
  13 + @root_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "../..")
  14 + end
  15 +
  16 + def pidfile
  17 + "#{root_path}/tmp/pids/sidekiq.pid"
  18 + end
  19 +
  20 + def rails_env
  21 + ENV['RAILS_ENV'] || "production"
  22 + end
  23 +end
resque.sh
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -mkdir -p tmp/pids  
2 -nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook RAILS_ENV=production PIDFILE=tmp/pids/resque_worker.pid > ./log/resque.stdout.log 2>./log/resque.stderr.log &  
3 \ No newline at end of file 0 \ No newline at end of file
resque_dev.sh
@@ -1,2 +0,0 @@ @@ -1,2 +0,0 @@
1 -mkdir -p tmp/pids  
2 -nohup bundle exec rake environment resque:work QUEUE=post_receive,mailer,system_hook VVERBOSE=1 RAILS_ENV=development PIDFILE=tmp/pids/resque_worker.pid > ./log/resque.log &