Commit 22c02bc2 authored by Sean McGivern's avatar Sean McGivern

Merge branch '36119-issuable-workers' into 'master'

Simplify checking if objects exist code in new issaubles workers

Closes #36119

See merge request !13365
parents 97b2c7c6 947c09c2
......@@ -16,6 +16,7 @@ module Issues
spam_check(issue, current_user)
issue.move_to_end
# current_user (defined in BaseService) is not available within run_after_commit block
user = current_user
issue.run_after_commit do
NewIssueWorker.perform_async(issue.id, user.id)
......
......@@ -17,6 +17,7 @@ module MergeRequests
end
def before_create(merge_request)
# current_user (defined in BaseService) is not available within run_after_commit block
user = current_user
merge_request.run_after_commit do
NewMergeRequestWorker.perform_async(merge_request.id, user.id)
......
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)
......
......@@ -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)
......
......@@ -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)
......
---
title: Simplify checking if objects exist code in new issaubles workers
merge_request:
author:
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment