diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 09:55:51 +0000 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/models/ci/pipeline.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) | |
download | gitlab-ce-e8d2c2579383897a1dd7f9debd359abe8ae8373d.tar.gz |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/models/ci/pipeline.rb')
-rw-r--r-- | app/models/ci/pipeline.rb | 71 |
1 files changed, 34 insertions, 37 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 159d9d10878..5d079f57267 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -29,6 +29,8 @@ module Ci BridgeStatusError = Class.new(StandardError) + paginates_per 15 + sha_attribute :source_sha sha_attribute :target_sha @@ -222,7 +224,7 @@ module Ci end after_transition [:created, :waiting_for_resource, :preparing, :pending, :running] => :success do |pipeline| - # We wait a little bit to ensure that all BuildFinishedWorkers finish first + # We wait a little bit to ensure that all Ci::BuildFinishedWorkers finish first # because this is where some metrics like code coverage is parsed and stored # in CI build records which the daily build metrics worker relies on. pipeline.run_after_commit { Ci::DailyBuildGroupReportResultsWorker.perform_in(10.minutes, pipeline.id) } @@ -577,11 +579,11 @@ module Ci canceled? && auto_canceled_by_id? end - def cancel_running(retries: nil) + def cancel_running(retries: 1) commit_status_relations = [:project, :pipeline] ci_build_relations = [:deployment, :taggings] - retry_optimistic_lock(cancelable_statuses, retries, name: 'ci_pipeline_cancel_running') do |cancelables| + retry_lock(cancelable_statuses, retries, name: 'ci_pipeline_cancel_running') do |cancelables| cancelables.find_in_batches do |batch| ActiveRecord::Associations::Preloader.new.preload(batch, commit_status_relations) ActiveRecord::Associations::Preloader.new.preload(batch.select { |job| job.is_a?(Ci::Build) }, ci_build_relations) @@ -594,7 +596,7 @@ module Ci end end - def auto_cancel_running(pipeline, retries: nil) + def auto_cancel_running(pipeline, retries: 1) update(auto_canceled_by: pipeline) cancel_running(retries: retries) do |job| @@ -610,8 +612,6 @@ module Ci # rubocop: enable CodeReuse/ServiceClass def lazy_ref_commit - return unless ::Gitlab::Ci::Features.pipeline_latest? - BatchLoader.for(ref).batch do |refs, loader| next unless project.repository_exists? @@ -623,11 +623,6 @@ module Ci def latest? return false unless git_ref && commit.present? - - unless ::Gitlab::Ci::Features.pipeline_latest? - return project.commit(git_ref) == commit - end - return false if lazy_ref_commit.nil? lazy_ref_commit.id == commit.id @@ -861,7 +856,7 @@ module Ci def execute_hooks project.execute_hooks(pipeline_data, :pipeline_hooks) if project.has_active_hooks?(:pipeline_hooks) - project.execute_services(pipeline_data, :pipeline_hooks) if project.has_active_services?(:pipeline_hooks) + project.execute_integrations(pipeline_data, :pipeline_hooks) if project.has_active_integrations?(:pipeline_hooks) end # All the merge requests for which the current pipeline runs/ran against @@ -911,7 +906,7 @@ module Ci def same_family_pipeline_ids ::Gitlab::Ci::PipelineObjectHierarchy.new( - self.class.default_scoped.where(id: root_ancestor), options: { same_project: true } + self.class.default_scoped.where(id: root_ancestor), options: { project_condition: :same } ).base_and_descendants.select(:id) end @@ -932,29 +927,34 @@ module Ci Environment.where(id: environment_ids) end - # Without using `unscoped`, caller scope is also included into the query. - # Using `unscoped` here will be redundant after Rails 6.1 + # With multi-project and parent-child pipelines + def self_and_upstreams + object_hierarchy.base_and_ancestors + end + + # With multi-project and parent-child pipelines + def self_with_upstreams_and_downstreams + object_hierarchy.all_objects + end + + # With only parent-child pipelines + def self_and_ancestors + object_hierarchy(project_condition: :same).base_and_ancestors + end + + # With only parent-child pipelines def self_and_descendants - ::Gitlab::Ci::PipelineObjectHierarchy - .new(self.class.unscoped.where(id: id), options: { same_project: true }) - .base_and_descendants + object_hierarchy(project_condition: :same).base_and_descendants end def root_ancestor return self unless child? - Gitlab::Ci::PipelineObjectHierarchy - .new(self.class.unscoped.where(id: id), options: { same_project: true }) + object_hierarchy(project_condition: :same) .base_and_ancestors(hierarchy_order: :desc) .first end - def self_with_ancestors_and_descendants(same_project: false) - ::Gitlab::Ci::PipelineObjectHierarchy - .new(self.class.unscoped.where(id: id), options: { same_project: same_project }) - .all_objects - end - def bridge_triggered? source_bridge.present? end @@ -1026,8 +1026,6 @@ module Ci end def can_generate_codequality_reports? - return false unless ::Gitlab::Ci::Features.display_quality_on_mr_diff?(project) - has_reports?(Ci::JobArtifact.codequality_reports) end @@ -1214,14 +1212,6 @@ module Ci self.ci_ref = Ci::Ref.ensure_for(self) end - def base_and_ancestors(same_project: false) - # Without using `unscoped`, caller scope is also included into the query. - # Using `unscoped` here will be redundant after Rails 6.1 - ::Gitlab::Ci::PipelineObjectHierarchy - .new(self.class.unscoped.where(id: id), options: { same_project: same_project }) - .base_and_ancestors - end - # We need `base_and_ancestors` in a specific order to "break" when needed. # If we use `find_each`, then the order is broken. # rubocop:disable Rails/FindEach @@ -1232,7 +1222,7 @@ module Ci source_bridge.pending! Ci::AfterRequeueJobService.new(project, current_user).execute(source_bridge) # rubocop:disable CodeReuse/ServiceClass else - base_and_ancestors.includes(:source_bridge).each do |pipeline| + self_and_upstreams.includes(:source_bridge).each do |pipeline| break unless pipeline.bridge_waiting? pipeline.source_bridge.pending! @@ -1315,6 +1305,13 @@ module Ci project.repository.keep_around(self.sha, self.before_sha) end + + # Without using `unscoped`, caller scope is also included into the query. + # Using `unscoped` here will be redundant after Rails 6.1 + def object_hierarchy(options = {}) + ::Gitlab::Ci::PipelineObjectHierarchy + .new(self.class.unscoped.where(id: id), options: options) + end end end |