Welcome to mirror list, hosted at ThFree Co, Russian Federation.

unlock_pipelines_in_queue_worker.rb « ci « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de57950471180f050b6b4ba20b6478c2c1cf2b17 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# frozen_string_literal: true

module Ci
  class UnlockPipelinesInQueueWorker
    include ApplicationWorker

    data_consistency :always # rubocop:disable SidekiqLoadBalancing/WorkerDataConsistency

    include LimitedCapacity::Worker

    feature_category :build_artifacts
    idempotent!

    MAX_RUNNING_LOW = 50
    MAX_RUNNING_MEDIUM = 500
    MAX_RUNNING_HIGH = 1500

    def perform_work(*_)
      pipeline_id, enqueue_timestamp = Ci::UnlockPipelineRequest.next!
      return log_extra_metadata_on_done(:remaining_pending, 0) unless pipeline_id

      Ci::Pipeline.find_by_id(pipeline_id).try do |pipeline|
        log_extra_metadata_on_done(:pipeline_id, pipeline.id)
        log_extra_metadata_on_done(:project, pipeline.project.full_path)

        result = Ci::UnlockPipelineService.new(pipeline).execute

        log_extra_metadata_on_done(:unlock_wait_time, Time.current.utc.to_i - enqueue_timestamp)
        log_extra_metadata_on_done(:remaining_pending, Ci::UnlockPipelineRequest.total_pending)
        log_extra_metadata_on_done(:skipped_already_leased, result[:skipped_already_leased])
        log_extra_metadata_on_done(:skipped_already_unlocked, result[:skipped_already_unlocked])
        log_extra_metadata_on_done(:exec_timeout, result[:exec_timeout])
        log_extra_metadata_on_done(:unlocked_job_artifacts, result[:unlocked_job_artifacts])
        log_extra_metadata_on_done(:unlocked_pipeline_artifacts, result[:unlocked_pipeline_artifacts])
      end
    end

    def remaining_work_count(*_)
      Ci::UnlockPipelineRequest.total_pending
    end

    def max_running_jobs
      if ::Feature.enabled?(:ci_unlock_pipelines_high, type: :ops)
        MAX_RUNNING_HIGH
      elsif ::Feature.enabled?(:ci_unlock_pipelines_medium, type: :ops)
        MAX_RUNNING_MEDIUM
      elsif ::Feature.enabled?(:ci_unlock_pipelines, type: :ops)
        # This is the default enabled flag
        MAX_RUNNING_LOW
      else
        0
      end
    end
  end
end