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-10-24 23:57:45 +05:30
|
|
|
def execute
|
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-10-24 23:57:45 +05:30
|
|
|
Ci::PipelineProcessing::AtomicProcessingService
|
|
|
|
.new(pipeline)
|
|
|
|
.execute
|
2019-10-12 21:52:04 +05:30
|
|
|
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
|
2021-01-03 14:25:43 +05:30
|
|
|
latest_statuses = pipeline.latest_statuses
|
2017-08-17 22:00:37 +05:30
|
|
|
.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
|
2020-11-24 15:15:51 +05:30
|
|
|
if latest_statuses.any?
|
2021-01-03 14:25:43 +05:30
|
|
|
pipeline.latest_statuses
|
2020-11-24 15:15:51 +05:30
|
|
|
.where(name: latest_statuses.map(&:second))
|
|
|
|
.where.not(id: latest_statuses.map(&:first))
|
|
|
|
.update_all(retried: true)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|