Commit 6ac73f45f0d88b4a7fded64260a8d6ea1cff7400
1 parent
fc3878c0
Exists in
master
and in
4 other branches
Move EmailOnPush logic to async worker
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
26 additions
and
19 deletions
Show diff stats
app/models/project_services/emails_on_push_service.rb
... | ... | @@ -33,24 +33,7 @@ class EmailsOnPushService < Service |
33 | 33 | end |
34 | 34 | |
35 | 35 | def execute(push_data) |
36 | - before_sha = push_data[:before] | |
37 | - after_sha = push_data[:after] | |
38 | - branch = push_data[:ref] | |
39 | - author_id = push_data[:user_id] | |
40 | - | |
41 | - if before_sha =~ /^000000/ || after_sha =~ /^000000/ | |
42 | - # skip if new branch was pushed or branch was removed | |
43 | - return true | |
44 | - end | |
45 | - | |
46 | - compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) | |
47 | - | |
48 | - # Do not send emails if git compare failed | |
49 | - return false unless compare && compare.commits.present? | |
50 | - | |
51 | - recipients.split(" ").each do |recipient| | |
52 | - Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) | |
53 | - end | |
36 | + EmailsOnPushWorker.perform_async(project_id, recipients, push_data) | |
54 | 37 | end |
55 | 38 | |
56 | 39 | def fields |
... | ... | @@ -59,4 +42,3 @@ class EmailsOnPushService < Service |
59 | 42 | ] |
60 | 43 | end |
61 | 44 | end |
62 | - | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +class EmailsOnPushWorker | |
2 | + include Sidekiq::Worker | |
3 | + | |
4 | + def perform(project_id, recipients, push_data) | |
5 | + project = Project.find(project_id) | |
6 | + before_sha = push_data["before"] | |
7 | + after_sha = push_data["after"] | |
8 | + branch = push_data["ref"] | |
9 | + author_id = push_data["user_id"] | |
10 | + | |
11 | + if before_sha =~ /^000000/ || after_sha =~ /^000000/ | |
12 | + # skip if new branch was pushed or branch was removed | |
13 | + return true | |
14 | + end | |
15 | + | |
16 | + compare = Gitlab::Git::Compare.new(project.repository.raw_repository, before_sha, after_sha) | |
17 | + | |
18 | + # Do not send emails if git compare failed | |
19 | + return false unless compare && compare.commits.present? | |
20 | + | |
21 | + recipients.split(" ").each do |recipient| | |
22 | + Notify.delay.repository_push_email(project_id, recipient, author_id, branch, compare) | |
23 | + end | |
24 | + end | |
25 | +end | ... | ... |