summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-03-15 15:10:49 +0000
committerDouwe Maan <douwe@gitlab.com>2016-03-15 15:10:49 +0000
commita628db7b4d8c83a80d3151ba7a4c3d694b1a678c (patch)
treebd6c3beb67f8cf36f29d3dbd420b06ab7bcaa1e4 /app
parent7196ee1095767c0adc7c41f92905b035609d0304 (diff)
parent76350e2ede187a8bd15e343c30537c90ee557aa7 (diff)
downloadgitlab-ce-a628db7b4d8c83a80d3151ba7a4c3d694b1a678c.tar.gz
Merge branch 'fix/ensure-no-new_ssh_key_email-dead-jobs' into 'master'
Ensure "new SSH key" email do not ends up as dead Sidekiq jobs Related to #2235. This is done by: 1. Delaying the notification sending after the SSH key is commited in DB 2. Gracefully exit the mailer method if the record cannot be found /cc @dblessing @stanhu @DouweM See merge request !3163
Diffstat (limited to 'app')
-rw-r--r--app/mailers/emails/profile.rb5
-rw-r--r--app/models/key.rb3
2 files changed, 6 insertions, 2 deletions
diff --git a/app/mailers/emails/profile.rb b/app/mailers/emails/profile.rb
index 3a83b083109..256cbcd73a1 100644
--- a/app/mailers/emails/profile.rb
+++ b/app/mailers/emails/profile.rb
@@ -14,7 +14,10 @@ module Emails
end
def new_ssh_key_email(key_id)
- @key = Key.find(key_id)
+ @key = Key.find_by_id(key_id)
+
+ return unless @key
+
@current_user = @user = @key.user
@target_url = user_url(@user)
mail(to: @user.notification_email, subject: subject("SSH key was added to your account"))
diff --git a/app/models/key.rb b/app/models/key.rb
index 406a1257b5d..0282ad18139 100644
--- a/app/models/key.rb
+++ b/app/models/key.rb
@@ -16,6 +16,7 @@
require 'digest/md5'
class Key < ActiveRecord::Base
+ include AfterCommitQueue
include Sortable
belongs_to :user
@@ -62,7 +63,7 @@ class Key < ActiveRecord::Base
end
def notify_user
- NotificationService.new.new_key(self)
+ run_after_commit { NotificationService.new.new_key(self) }
end
def post_create_hook