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

enqueue_pipelines_to_unlock_service.rb « refs « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 319186ce0304ede1b532f8be1b7d6c3455156398 (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
# frozen_string_literal: true

module Ci
  module Refs
    class EnqueuePipelinesToUnlockService
      include BaseServiceUtility

      BATCH_SIZE = 50
      ENQUEUE_INTERVAL_SECONDS = 0.1

      def execute(ci_ref, before_pipeline: nil)
        pipelines_scope = ci_ref.pipelines.artifacts_locked
        pipelines_scope = pipelines_scope.before_pipeline(before_pipeline) if before_pipeline
        total_new_entries = 0

        pipelines_scope.each_batch(of: BATCH_SIZE) do |batch|
          pipeline_ids = batch.pluck(:id) # rubocop: disable CodeReuse/ActiveRecord
          total_added = Ci::UnlockPipelineRequest.enqueue(pipeline_ids)
          total_new_entries += total_added

          # Take a little rest to avoid overloading Redis
          sleep ENQUEUE_INTERVAL_SECONDS
        end

        success(
          total_pending_entries: Ci::UnlockPipelineRequest.total_pending,
          total_new_entries: total_new_entries
        )
      end
    end
  end
end