Move some issue after creation tasks to async job

parent f82a9c95
......@@ -32,13 +32,17 @@ module Issues
end
end
# Add new items to Issues::AfterCreateService if they can be performed in Sidekiq
def after_create(issue)
add_incident_label(issue)
todo_service.new_issue(issue, current_user)
user_agent_detail_service.create
resolve_discussions_with_issue(issue)
delete_milestone_total_issue_counter_cache(issue.milestone)
track_incident_action(current_user, issue, :incident_created)
if Feature.disabled?(:issue_perform_after_creation_tasks_async, issue.project)
Issues::AfterCreateService
.new(issue.project, current_user)
.execute(issue)
end
super
end
......@@ -77,4 +81,4 @@ module Issues
end
end
Issues::CreateService.prepend_if_ee('EE::Issues::CreateService')
Issues::CreateService.prepend_ee_mod
......@@ -14,7 +14,14 @@ class NewIssueWorker # rubocop:disable Scalability/IdempotentWorker
::EventCreateService.new.open_issue(issuable, user)
::NotificationService.new.new_issue(issuable, user)
issuable.create_cross_references!(user)
if Feature.enabled?(:issue_perform_after_creation_tasks_async, issuable.project)
Issues::AfterCreateService
.new(issuable.project, user)
.execute(issuable)
end
end
def issuable_class
......
---
name: issue_perform_after_creation_tasks_async
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58588
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/21140
milestone: '13.11'
type: development
group: group::geo
default_enabled: false
......@@ -31,6 +31,7 @@ module EE
private
def add_issue_sla(issue)
return if ::Feature.enabled?(:issue_perform_after_creation_tasks_async, issue.project)
return unless issue.sla_available?
::IncidentManagement::Incidents::CreateSlaService.new(issue, current_user).execute
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe Issues::CreateService do
include AfterNextHelpers
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { create(:user) }
......@@ -64,7 +66,6 @@ RSpec.describe Issues::CreateService do
it_behaves_like 'incident issue'
it_behaves_like 'has incident label'
it_behaves_like 'an incident management tracked event', :incident_management_incident_created
it 'does create an incident label' do
expect { subject }
......@@ -112,25 +113,35 @@ RSpec.describe Issues::CreateService do
end
end
it 'creates a pending todo for new assignee' do
attributes = {
project: project,
author: user,
user: assignee,
target_id: issue.id,
target_type: issue.class.name,
action: Todo::ASSIGNED,
state: :pending
}
it 'moves the issue to the end, in an asynchronous worker' do
expect(IssuePlacementWorker).to receive(:perform_async).with(be_nil, Integer)
expect(Todo.where(attributes).count).to eq 1
described_class.new(project, user, opts).execute
end
it 'moves the issue to the end, in an asynchronous worker' do
expect(IssuePlacementWorker).to receive(:perform_async).with(be_nil, Integer)
context 'with issue_perform_after_creation_tasks_async feature disabled' do
before do
stub_feature_flags(issue_perform_after_creation_tasks_async: false)
end
it 'calls Issues::AfterCreateService' do
expect_next(::Issues::AfterCreateService, project, user).to receive(:execute)
described_class.new(project, user, opts).execute
end
end
context 'with issue_perform_after_creation_tasks_async feature enabled' do
before do
stub_feature_flags(issue_perform_after_creation_tasks_async: true)
end
it 'does not call Issues::AfterCreateService' do
expect(::Issues::AfterCreateService).not_to receive(:new)
described_class.new(project, user, opts).execute
end
end
context 'when label belongs to project group' do
let(:group) { create(:group) }
......@@ -279,14 +290,6 @@ RSpec.describe Issues::CreateService do
end
end
it 'deletes milestone issues count cache' do
expect_next_instance_of(Milestones::IssuesCountService, milestone) do |service|
expect(service).to receive(:delete_cache).and_call_original
end
issue
end
it 'schedules a namespace onboarding create action worker' do
expect(Namespaces::OnboardingIssueCreatedWorker).to receive(:perform_async).with(project.namespace.id)
......
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe NewIssueWorker do
include AfterNextHelpers
describe '#perform' do
let(:worker) { described_class.new }
......@@ -80,6 +82,31 @@ RSpec.describe NewIssueWorker do
worker.perform(issue.id, user.id)
end
context 'with issue_perform_after_creation_tasks_async feature disabled' do
before do
stub_feature_flags(issue_perform_after_creation_tasks_async: false)
end
it 'does not call Issues::AfterCreateService' do
expect(::Issues::AfterCreateService).not_to receive(:execute)
worker.perform(issue.id, user.id)
end
end
context 'with issue_perform_after_creation_tasks_async feature enabled' do
before do
stub_feature_flags(issue_perform_after_creation_tasks_async: true)
end
it 'calls Issues::AfterCreateService' do
expect_next(::Issues::AfterCreateService)
.to receive(:execute)
worker.perform(issue.id, user.id)
end
end
end
end
end
......
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