From 851d2a51c359f55be8b94083d7784a9358b67791 Mon Sep 17 00:00:00 2001 From: hustewart Date: Tue, 4 Jun 2024 14:33:12 -0400 Subject: [PATCH] Sync code owner approval rules async This commit changes the sync from happening synchronously to asynchronously in order to avoid time outs in projects where there are many MRs. --- .../services/ee/protected_branches/create_service.rb | 2 +- .../ee/protected_branches/create_service_spec.rb | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ee/app/services/ee/protected_branches/create_service.rb b/ee/app/services/ee/protected_branches/create_service.rb index 1d805af70c63bc..75da62e6ca6fa1 100644 --- a/ee/app/services/ee/protected_branches/create_service.rb +++ b/ee/app/services/ee/protected_branches/create_service.rb @@ -34,7 +34,7 @@ def sync_code_owner_approval_rules return unless project_or_group.feature_available?(:code_owners) merge_requests_for_protected_branch.each do |merge_request| - ::MergeRequests::SyncCodeOwnerApprovalRules.new(merge_request).execute + ::MergeRequests::SyncCodeOwnerApprovalRulesWorker.perform_async(merge_request.id) end end diff --git a/ee/spec/services/ee/protected_branches/create_service_spec.rb b/ee/spec/services/ee/protected_branches/create_service_spec.rb index 5dc4f2aac7ae7a..a446d030adb5cb 100644 --- a/ee/spec/services/ee/protected_branches/create_service_spec.rb +++ b/ee/spec/services/ee/protected_branches/create_service_spec.rb @@ -121,7 +121,10 @@ end it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs", :aggregate_failures do - expect(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original + expect(::MergeRequests::SyncCodeOwnerApprovalRulesWorker) + .to receive(:perform_async) + .with(merge_request.id) + .and_call_original expect { service.execute }.to change(ProtectedBranch, :count).by(1) end @@ -133,7 +136,10 @@ end it "calls MergeRequest::SyncCodeOwnerApprovalRules to update open MRs", :aggregate_failures do - expect(::MergeRequests::SyncCodeOwnerApprovalRules).to receive(:new).with(merge_request).and_call_original + expect(::MergeRequests::SyncCodeOwnerApprovalRulesWorker) + .to receive(:perform_async) + .with(merge_request.id) + .and_call_original expect { service.execute }.to change(ProtectedBranch, :count).by(1) end end -- GitLab