summaryrefslogtreecommitdiff
path: root/app/workers
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-08-09 11:54:03 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-08-09 11:54:03 +0000
commit22c02bc22aff28150d6f8acb9b789ca25fc2ed11 (patch)
treeb58f7ad0f89b721ea524f8131a0b8e33db4136f6 /app/workers
parent97b2c7c6333e2ec889874a670996bd0d0866bf51 (diff)
parent947c09c2a6f8cc9c4b3606efb326aa4912095e7d (diff)
downloadgitlab-ce-22c02bc22aff28150d6f8acb9b789ca25fc2ed11.tar.gz
Merge branch '36119-issuable-workers' into 'master'
Simplify checking if objects exist code in new issaubles workers Closes #36119 See merge request !13365
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/concerns/new_issuable.rb25
-rw-r--r--app/workers/new_issue_worker.rb2
-rw-r--r--app/workers/new_merge_request_worker.rb2
3 files changed, 16 insertions, 13 deletions
diff --git a/app/workers/concerns/new_issuable.rb b/app/workers/concerns/new_issuable.rb
index 3fd472bf0c1..eb0d6c9c36c 100644
--- a/app/workers/concerns/new_issuable.rb
+++ b/app/workers/concerns/new_issuable.rb
@@ -1,20 +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
+ def objects_found?(issuable_id, user_id)
+ set_user(user_id)
+ set_issuable(issuable_id)
+
+ user && issuable
+ end
+ def set_user(user_id)
@user = User.find_by(id: user_id)
- unless @user
- log_error(User, user_id)
- return false
- end
- true
+ log_error(User, user_id) unless @user
+ end
+
+ def set_issuable(issuable_id)
+ @issuable = issuable_class.find_by(id: issuable_id)
+
+ log_error(issuable_class, issuable_id) unless @issuable
end
def log_error(record_class, record_id)
diff --git a/app/workers/new_issue_worker.rb b/app/workers/new_issue_worker.rb
index 19a778ad522..d9a8e892e90 100644
--- a/app/workers/new_issue_worker.rb
+++ b/app/workers/new_issue_worker.rb
@@ -4,7 +4,7 @@ class NewIssueWorker
include NewIssuable
def perform(issue_id, user_id)
- return unless ensure_objects_found(issue_id, user_id)
+ return unless objects_found?(issue_id, user_id)
EventCreateService.new.open_issue(issuable, user)
NotificationService.new.new_issue(issuable, user)
diff --git a/app/workers/new_merge_request_worker.rb b/app/workers/new_merge_request_worker.rb
index 3c8a68016ff..1910c490159 100644
--- a/app/workers/new_merge_request_worker.rb
+++ b/app/workers/new_merge_request_worker.rb
@@ -4,7 +4,7 @@ class NewMergeRequestWorker
include NewIssuable
def perform(merge_request_id, user_id)
- return unless ensure_objects_found(merge_request_id, user_id)
+ return unless objects_found?(merge_request_id, user_id)
EventCreateService.new.open_mr(issuable, user)
NotificationService.new.new_merge_request(issuable, user)