2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Ci
|
2020-01-01 13:55:28 +05:30
|
|
|
class ProcessPipelineService
|
2016-09-13 17:45:13 +05:30
|
|
|
attr_reader :pipeline
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
def initialize(pipeline)
|
2016-09-13 17:45:13 +05:30
|
|
|
@pipeline = pipeline
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def execute(trigger_build_ids = nil, initial_process: false)
|
2020-07-28 23:09:34 +05:30
|
|
|
increment_processing_counter
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
update_retried
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
if ::Gitlab::Ci::Features.atomic_processing?(pipeline.project)
|
2020-03-13 15:44:24 +05:30
|
|
|
Ci::PipelineProcessing::AtomicProcessingService
|
|
|
|
.new(pipeline)
|
|
|
|
.execute
|
2019-10-12 21:52:04 +05:30
|
|
|
else
|
2020-03-13 15:44:24 +05:30
|
|
|
Ci::PipelineProcessing::LegacyProcessingService
|
|
|
|
.new(pipeline)
|
|
|
|
.execute(trigger_build_ids, initial_process: initial_process)
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def metrics
|
|
|
|
@metrics ||= ::Gitlab::Ci::Pipeline::Metrics.new
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
private
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
# This method is for compatibility and data consistency and should be removed with 9.3 version of GitLab
|
|
|
|
# This replicates what is db/post_migrate/20170416103934_upate_retried_for_ci_build.rb
|
|
|
|
# and ensures that functionality will not be broken before migration is run
|
|
|
|
# this updates only when there are data that needs to be updated, there are two groups with no retried flag
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2017-08-17 22:00:37 +05:30
|
|
|
def update_retried
|
|
|
|
# find the latest builds for each name
|
|
|
|
latest_statuses = pipeline.statuses.latest
|
|
|
|
.group(:name)
|
|
|
|
.having('count(*) > 1')
|
2019-09-30 21:07:59 +05:30
|
|
|
.pluck(Arel.sql('MAX(id)'), 'name')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
# mark builds that are retried
|
|
|
|
pipeline.statuses.latest
|
|
|
|
.where(name: latest_statuses.map(&:second))
|
|
|
|
.where.not(id: latest_statuses.map(&:first))
|
|
|
|
.update_all(retried: true) if latest_statuses.any?
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
def increment_processing_counter
|
|
|
|
metrics.pipeline_processing_events_counter.increment
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|