Class: Ci::DropPipelineService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/drop_pipeline_service.rb

Constant Summary collapse

PRELOADED_RELATIONS =
[:project, :pipeline, :metadata, :deployment, :taggings].freeze

Instance Method Summary collapse

Instance Method Details

#execute(pipeline, failure_reason, retries: 3) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/ci/drop_pipeline_service.rb', line 18

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

#execute_async_for_all(pipelines, failure_reason, context_user) ⇒ Object

execute service asynchronously for each cancelable pipeline



8
9
10
11
12
13
14
15
16
# File 'app/services/ci/drop_pipeline_service.rb', line 8

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