diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-07 21:21:29 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-08-07 21:21:29 +0000 |
commit | c94990820a2ea3cfc16099e318fcce5354a3c052 (patch) | |
tree | 2ea9dd5333d8ea7a3b00e7b7e81ece014da679d6 /app/workers | |
parent | 44131d5c2adfbf2dde16bba6621143037409c68b (diff) | |
parent | 9ef3c431e4859e1bc03267735b956d5920d5dd42 (diff) | |
download | gitlab-ce-c94990820a2ea3cfc16099e318fcce5354a3c052.tar.gz |
Merge branch '32844-issuables-performance' into 'master'
Issuables: Move some code from create services to Sidekiq workers
See merge request !13326
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/concerns/new_issuable.rb | 23 | ||||
-rw-r--r-- | app/workers/new_issue_worker.rb | 17 | ||||
-rw-r--r-- | app/workers/new_merge_request_worker.rb | 17 |
3 files changed, 57 insertions, 0 deletions
diff --git a/app/workers/concerns/new_issuable.rb b/app/workers/concerns/new_issuable.rb new file mode 100644 index 00000000000..3fd472bf0c1 --- /dev/null +++ b/app/workers/concerns/new_issuable.rb @@ -0,0 +1,23 @@ +module NewIssuable + attr_reader :issuable, :user + + def ensure_objects_found(issuable_id, user_id) + @issuable = issuable_class.find_by(id: issuable_id) + unless @issuable + log_error(issuable_class, issuable_id) + return false + end + + @user = User.find_by(id: user_id) + unless @user + log_error(User, user_id) + return false + end + + true + end + + def log_error(record_class, record_id) + Rails.logger.error("#{self.class}: couldn't find #{record_class} with ID=#{record_id}, skipping job") + end +end diff --git a/app/workers/new_issue_worker.rb b/app/workers/new_issue_worker.rb new file mode 100644 index 00000000000..19a778ad522 --- /dev/null +++ b/app/workers/new_issue_worker.rb @@ -0,0 +1,17 @@ +class NewIssueWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + include NewIssuable + + def perform(issue_id, user_id) + return unless ensure_objects_found(issue_id, user_id) + + EventCreateService.new.open_issue(issuable, user) + NotificationService.new.new_issue(issuable, user) + issuable.create_cross_references!(user) + end + + def issuable_class + Issue + end +end diff --git a/app/workers/new_merge_request_worker.rb b/app/workers/new_merge_request_worker.rb new file mode 100644 index 00000000000..3c8a68016ff --- /dev/null +++ b/app/workers/new_merge_request_worker.rb @@ -0,0 +1,17 @@ +class NewMergeRequestWorker + include Sidekiq::Worker + include DedicatedSidekiqQueue + include NewIssuable + + def perform(merge_request_id, user_id) + return unless ensure_objects_found(merge_request_id, user_id) + + EventCreateService.new.open_mr(issuable, user) + NotificationService.new.new_merge_request(issuable, user) + issuable.create_cross_references!(user) + end + + def issuable_class + MergeRequest + end +end |