Class: Ci::AbortPipelinesService

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

Instance Method Summary collapse

Instance Method Details

#execute(pipelines, failure_reason) ⇒ Object

NOTE: This call fails pipelines in bulk without running callbacks. Only for pipeline abandonment scenarios (examples: project delete)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/ci/abort_pipelines_service.rb', line 7

def execute(pipelines, failure_reason)
  pipelines.cancelable.each_batch(of: 100) do |pipeline_batch|
    now = Time.current

    basic_attributes = { status: :failed }
    all_attributes = basic_attributes.merge(failure_reason: failure_reason, finished_at: now)

    bulk_fail_for(Ci::Stage, pipeline_batch, basic_attributes)
    bulk_fail_for(CommitStatus, pipeline_batch, all_attributes)

    pipeline_batch.update_all(all_attributes)
  end

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