debian-mirror-gitlab/app/services/ci/drop_pipeline_service.rb

37 lines
1.2 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Ci
class DropPipelineService
2021-11-11 11:23:49 +05:30
PRELOADED_RELATIONS = [:project, :pipeline, :metadata, :deployment, :taggings].freeze
2021-10-27 15:23:28 +05:30
2021-04-29 21:17:54 +05:30
# execute service asynchronously for each cancelable pipeline
def execute_async_for_all(pipelines, failure_reason, context_user)
pipelines.cancelable.select(:id).find_in_batches do |pipelines_batch|
Ci::DropPipelineWorker.bulk_perform_async_with_contexts(
pipelines_batch,
arguments_proc: -> (pipeline) { [pipeline.id, failure_reason] },
context_proc: -> (_) { { user: context_user } }
)
end
end
def execute(pipeline, failure_reason, retries: 3)
Gitlab::OptimisticLocking.retry_lock(pipeline.cancelable_statuses, retries, name: 'ci_pipeline_drop_running') do |cancelables|
cancelables.find_in_batches do |batch|
preload_associations_for_drop(batch)
batch.each do |job|
job.drop(failure_reason)
end
end
end
end
private
2021-10-27 15:23:28 +05:30
def preload_associations_for_drop(commit_status_batch)
2021-11-11 11:23:49 +05:30
Preloaders::CommitStatusPreloader.new(commit_status_batch).execute(PRELOADED_RELATIONS)
2021-04-29 21:17:54 +05:30
end
end
end