diff options
Diffstat (limited to 'app/workers/merge_requests')
-rw-r--r-- | app/workers/merge_requests/cleanup_ref_worker.rb | 35 | ||||
-rw-r--r-- | app/workers/merge_requests/mergeability_check_batch_worker.rb | 15 |
2 files changed, 49 insertions, 1 deletions
diff --git a/app/workers/merge_requests/cleanup_ref_worker.rb b/app/workers/merge_requests/cleanup_ref_worker.rb new file mode 100644 index 00000000000..c714b976a2b --- /dev/null +++ b/app/workers/merge_requests/cleanup_ref_worker.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module MergeRequests + class CleanupRefWorker + include ApplicationWorker + include Projects::RemoveRefs + + sidekiq_options retry: 3 + loggable_arguments 2 + feature_category :code_review_workflow + + idempotent! + deduplicate :until_executed, if_deduplicated: :reschedule_once, ttl: 1.minute + data_consistency :delayed + + urgency :low + + # Even though this worker is de-duplicated we need to acquire lock + # on a project to avoid running many concurrent refs removals + # + # TODO: Once underlying fix is done we can remove `in_lock` + # + # Related to: + # - https://gitlab.com/gitlab-org/gitaly/-/issues/5368 + # - https://gitlab.com/gitlab-org/gitaly/-/issues/5369 + def perform(merge_request_id, only) + merge_request = MergeRequest.find_by_id(merge_request_id) + return unless merge_request + + serialized_remove_refs(merge_request.target_project_id) do + merge_request.cleanup_refs(only: only.to_sym) + end + end + end +end diff --git a/app/workers/merge_requests/mergeability_check_batch_worker.rb b/app/workers/merge_requests/mergeability_check_batch_worker.rb index cbe34ac3790..f48e9c234ab 100644 --- a/app/workers/merge_requests/mergeability_check_batch_worker.rb +++ b/app/workers/merge_requests/mergeability_check_batch_worker.rb @@ -15,10 +15,16 @@ module MergeRequests @logger ||= Sidekiq.logger end - def perform(merge_request_ids) + def perform(merge_request_ids, user_id) merge_requests = MergeRequest.id_in(merge_request_ids) + user = User.find_by_id(user_id) merge_requests.each do |merge_request| + # Skip projects that user doesn't have update_merge_request access + next if merge_status_recheck_not_allowed?(merge_request, user) + + merge_request.mark_as_checking + result = merge_request.check_mergeability next unless result&.error? @@ -30,5 +36,12 @@ module MergeRequests ) end end + + private + + def merge_status_recheck_not_allowed?(merge_request, user) + ::Feature.enabled?(:restrict_merge_status_recheck, merge_request.project) && + !Ability.allowed?(user, :update_merge_request, merge_request.project) + end end end |