File: auto_merge_process_worker.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (40 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

class AutoMergeProcessWorker # rubocop:disable Scalability/IdempotentWorker
  include ApplicationWorker

  data_consistency :sticky, feature_flag: :auto_merge_process_worker_sticky

  sidekiq_options retry: 3

  # Avoid _simultaneous execution_ of this job for the same MR,
  # but reschedule the second job just in case the first fails.
  deduplicate :until_executed, if_deduplicated: :reschedule_once

  queue_namespace :auto_merge
  feature_category :continuous_delivery
  worker_resource_boundary :cpu

  def perform(params = {})
    # Passing an integer id to AutoMergeProcessWorker is deprecated.
    # This is here to support existing implementations while we transition
    # to a params hash. https://gitlab.com/gitlab-org/gitlab/-/issues/497247
    params = { 'merge_request_id' => params } unless params.is_a?(Hash)

    merge_requests = params['merge_request_id'].try do |mr_id|
      MergeRequest.id_in(mr_id)
    end

    pipeline_merge_requests = params['pipeline_id'].try do |pipe_id|
      Ci::Pipeline.id_in(pipe_id).flat_map do |pipeline|
        pipeline.all_merge_requests.with_auto_merge_enabled
      end
    end

    all_merge_requests = merge_requests.to_a + pipeline_merge_requests.to_a

    all_merge_requests.each do |merge_request|
      AutoMergeService.new(merge_request.project, merge_request.merge_user).process(merge_request)
    end
  end
end