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

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

module Ci
  class AbortProjectPipelinesService
    # Danger: Cancels in bulk without callbacks
    # Only for pipeline abandonment scenarios (current example: project delete)
    def execute(project)
      return unless Feature.enabled?(:abort_deleted_project_pipelines, default_enabled: :yaml)

      pipelines = project.all_pipelines.cancelable
      bulk_abort!(pipelines, status: :canceled)

      ServiceResponse.success(message: 'Pipelines canceled')
    end

    private

    def bulk_abort!(pipelines, status:)
      pipelines.each_batch do |pipeline_batch|
        CommitStatus.in_pipelines(pipeline_batch).in_batches.update_all(status: status) # rubocop: disable Cop/InBatches
        pipeline_batch.update_all(status: status)
      end
    end
  end
end