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

67 lines
2.2 KiB
Ruby
Raw Normal View History

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
2021-04-29 21:17:54 +05:30
@metrics ||= ::Gitlab::Ci::Pipeline::Metrics
2020-07-28 23:09:34 +05:30
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
2021-04-17 20:07:23 +05:30
return if Feature.enabled?(:ci_remove_update_retried_from_process_pipeline, pipeline.project, default_enabled: :yaml)
2017-08-17 22:00:37 +05:30
# 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-03-11 19:13:27 +05:30
updated_count = pipeline.latest_statuses
.where(name: latest_statuses.map(&:second))
.where.not(id: latest_statuses.map(&:first))
.update_all(retried: true)
# This counter is temporary. It will be used to check whether if we still use this method or not
# after setting correct value of `GenericCommitStatus#retried`.
# More info: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50465#note_491657115
2021-06-08 01:23:25 +05:30
if updated_count > 0
Gitlab::AppJsonLogger.info(event: 'update_retried_is_used',
project_id: pipeline.project.id,
pipeline_id: pipeline.id)
metrics.legacy_update_jobs_counter.increment
end
2020-11-24 15:15:51 +05:30
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