Skip to content
Snippets Groups Projects
Commit 296b0a50 authored by Allison Browne's avatar Allison Browne :thermometer:
Browse files

Cleanup started statuses

Fix issues with extra non-applicable statuses in
the STARTED_STATUSES array
parent d2b2e94e
No related branches found
No related tags found
1 merge request!84605Remove scheduled and manual from STARTED_STATUSES constant
......@@ -336,7 +336,7 @@ class Pipeline < Ci::ApplicationRecord
scope :with_only_interruptible_builds, -> do
where('NOT EXISTS (?)',
Ci::Build.where('ci_builds.commit_id = ci_pipelines.id')
.with_status(:running, :success, :failed)
.with_status(STARTED_STATUSES)
.not_interruptible
)
end
......
......@@ -7,10 +7,7 @@ module HasStatus
DEFAULT_STATUS = 'created'
BLOCKED_STATUS = %w[manual scheduled].freeze
AVAILABLE_STATUSES = %w[created waiting_for_resource preparing pending running success failed canceled skipped manual scheduled].freeze
# TODO: replace STARTED_STATUSES with data from BUILD_STARTED_RUNNING_STATUSES in https://gitlab.com/gitlab-org/gitlab/-/issues/273378
# see https://gitlab.com/gitlab-org/gitlab/-/merge_requests/82149#note_865508501
BUILD_STARTED_RUNNING_STATUSES = %w[running success failed].freeze
STARTED_STATUSES = %w[running success failed skipped manual scheduled].freeze
STARTED_STATUSES = %w[running success failed].freeze
ACTIVE_STATUSES = %w[waiting_for_resource preparing pending running].freeze
COMPLETED_STATUSES = %w[success failed canceled skipped].freeze
ORDERED_STATUSES = %w[failed preparing pending running waiting_for_resource manual scheduled canceled success skipped created].freeze
......@@ -98,7 +95,7 @@ def completed_statuses
end
def started?
STARTED_STATUSES.include?(status) && started_at
STARTED_STATUSES.include?(status) && !!started_at
end
def active?
......
......@@ -45,12 +45,12 @@ def run(pipeline_tracker)
end
if ndjson_pipeline?(pipeline_tracker)
status = ExportStatus.new(pipeline_tracker, pipeline_tracker.pipeline_class.relation)
export_status = ExportStatus.new(pipeline_tracker, pipeline_tracker.pipeline_class.relation)
raise(Pipeline::ExpiredError, 'Pipeline timeout') if job_timeout?(pipeline_tracker)
raise(Pipeline::FailedError, status.error) if status.failed?
raise(Pipeline::FailedError, export_status.error) if export_status.failed?
return reenqueue(pipeline_tracker) if status.started?
return reenqueue(pipeline_tracker) if export_status.started?
end
pipeline_tracker.update!(status_event: 'start', jid: jid)
......
......@@ -106,7 +106,7 @@
create(:ci_build, :interruptible, :running, pipeline: child_pipeline)
end
not_started_statuses = Ci::HasStatus::AVAILABLE_STATUSES - Ci::HasStatus::BUILD_STARTED_RUNNING_STATUSES
not_started_statuses = Ci::HasStatus::AVAILABLE_STATUSES - Ci::HasStatus::STARTED_STATUSES
context 'when the jobs are cancelable' do
cancelable_not_started_statuses = Set.new(not_started_statuses).intersection(Ci::HasStatus::CANCELABLE_STATUSES)
cancelable_not_started_statuses.each do |status|
......
......@@ -150,26 +150,28 @@ def create_status(**opts)
commit_status.started_at = nil
end
it { is_expected.to be_falsey }
it { is_expected.to be(false) }
end
%w[running success failed].each do |status|
context "if commit status is #{status}" do
before do
commit_status.status = status
end
context 'with started_at' do
described_class::STARTED_STATUSES.each do |status|
context "if commit status is #{status}" do
before do
commit_status.status = status
end
it { is_expected.to be_truthy }
it { is_expected.to eq(true) }
end
end
end
%w[pending canceled].each do |status|
context "if commit status is #{status}" do
before do
commit_status.status = status
end
(described_class::AVAILABLE_STATUSES - described_class::STARTED_STATUSES).each do |status|
context "if commit status is #{status}" do
before do
commit_status.status = status
end
it { is_expected.to be_falsey }
it { is_expected.to be(false) }
end
end
end
end
......
......@@ -4,7 +4,7 @@
RSpec.describe Ci::JobEntity do
let(:user) { create(:user) }
let(:job) { create(:ci_build) }
let(:job) { create(:ci_build, :running) }
let(:project) { job.project }
let(:request) { double('request') }
......@@ -21,6 +21,11 @@
subject { entity.as_json }
it 'contains started' do
expect(subject).to include(:started)
expect(subject[:started]).to eq(true)
end
it 'contains complete to indicate if a pipeline is completed' do
expect(subject).to include(:complete)
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment