From f3eace454302bffca17c4164015641f53b764e3d Mon Sep 17 00:00:00 2001 From: Allison Browne <abrowne@gitlab.com> Date: Wed, 7 Feb 2024 15:54:08 -0500 Subject: [PATCH 1/2] Consolidate two scopes into one cancelable scope --- app/models/concerns/ci/has_status.rb | 6 +----- .../cancel_redundant_pipelines_service.rb | 2 +- spec/models/concerns/ci/has_status_spec.rb | 12 ------------ 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/app/models/concerns/ci/has_status.rb b/app/models/concerns/ci/has_status.rb index fb2b12e5f0045e..6cecb681ce2bc7 100644 --- a/app/models/concerns/ci/has_status.rb +++ b/app/models/concerns/ci/has_status.rb @@ -84,7 +84,7 @@ def stopped_statuses scope :manual, -> { with_status(:manual) } scope :scheduled, -> { with_status(:scheduled) } scope :alive, -> { with_status(*ALIVE_STATUSES) } - scope :alive_or_scheduled, -> { with_status(*klass::CANCELABLE_STATUSES) } + scope :cancelable, -> { with_status(*klass::CANCELABLE_STATUSES) } scope :created_or_pending, -> { with_status(:created, :pending) } scope :running_or_pending, -> { with_status(:running, :pending) } scope :finished, -> { with_status(:success, :failed, :canceled) } @@ -93,10 +93,6 @@ def stopped_statuses scope :incomplete, -> { without_statuses(completed_statuses) } scope :waiting_for_resource_or_upcoming, -> { with_status(:created, :scheduled, :waiting_for_resource) } - scope :cancelable, -> do - where(status: klass::CANCELABLE_STATUSES) - end - scope :without_statuses, -> (names) do with_status(all_state_names - names.to_a) end diff --git a/app/services/ci/pipeline_creation/cancel_redundant_pipelines_service.rb b/app/services/ci/pipeline_creation/cancel_redundant_pipelines_service.rb index 98469e82af3081..a5b76ab53c6b82 100644 --- a/app/services/ci/pipeline_creation/cancel_redundant_pipelines_service.rb +++ b/app/services/ci/pipeline_creation/cancel_redundant_pipelines_service.rb @@ -67,7 +67,7 @@ def parent_auto_cancelable_pipelines(ids) def parent_and_child_pipelines(ids) Ci::Pipeline.object_hierarchy(parent_auto_cancelable_pipelines(ids), project_condition: :same) .base_and_descendants - .alive_or_scheduled + .cancelable end def legacy_auto_cancel_pipelines(pipeline_ids) diff --git a/spec/models/concerns/ci/has_status_spec.rb b/spec/models/concerns/ci/has_status_spec.rb index 95f17c4f85478c..d1c92f886bf293 100644 --- a/spec/models/concerns/ci/has_status_spec.rb +++ b/spec/models/concerns/ci/has_status_spec.rb @@ -296,18 +296,6 @@ end end - describe '.alive_or_scheduled' do - subject { CommitStatus.alive_or_scheduled } - - %i[running pending waiting_for_callback waiting_for_resource preparing created scheduled].each do |status| - it_behaves_like 'containing the job', status - end - - %i[failed success canceled skipped].each do |status| - it_behaves_like 'not containing the job', status - end - end - describe '.created_or_pending' do subject { CommitStatus.created_or_pending } -- GitLab From 711bf7d84b76030b6663e4e69aa982d95adcba98 Mon Sep 17 00:00:00 2001 From: Allison Browne <abrowne@gitlab.com> Date: Fri, 23 Feb 2024 11:51:20 -0500 Subject: [PATCH 2/2] Fix SQL query --- app/models/concerns/ci/has_status.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/ci/has_status.rb b/app/models/concerns/ci/has_status.rb index 6cecb681ce2bc7..d14f6ea04bb1b4 100644 --- a/app/models/concerns/ci/has_status.rb +++ b/app/models/concerns/ci/has_status.rb @@ -84,7 +84,6 @@ def stopped_statuses scope :manual, -> { with_status(:manual) } scope :scheduled, -> { with_status(:scheduled) } scope :alive, -> { with_status(*ALIVE_STATUSES) } - scope :cancelable, -> { with_status(*klass::CANCELABLE_STATUSES) } scope :created_or_pending, -> { with_status(:created, :pending) } scope :running_or_pending, -> { with_status(:running, :pending) } scope :finished, -> { with_status(:success, :failed, :canceled) } @@ -93,6 +92,10 @@ def stopped_statuses scope :incomplete, -> { without_statuses(completed_statuses) } scope :waiting_for_resource_or_upcoming, -> { with_status(:created, :scheduled, :waiting_for_resource) } + scope :cancelable, -> do + where(status: klass::CANCELABLE_STATUSES) + end + scope :without_statuses, -> (names) do with_status(all_state_names - names.to_a) end -- GitLab