Commit 39704e39 authored by Kamil Trzciński's avatar Kamil Trzciński

Add feature flag

parent c6a7e95a
......@@ -23,7 +23,13 @@ module Ci
def status
strong_memoize(:status) do
@jobs.slow_composite_status
if Feature.enabled?(:ci_composite_status, default_enabled: true)
Gitlab::Ci::Status::GroupedStatuses
.new(@jobs)
.one[:status]
else
CommitStatus.where(id: @jobs).legacy_status
end
end
end
......
......@@ -31,7 +31,6 @@ module Ci
def status
@status ||= statuses.latest.slow_composite_status
end
def detailed_status(current_user)
......
......@@ -387,9 +387,24 @@ module Ci
end
end
def legacy_stages
def legacy_stages_using_sql
# TODO, this needs refactoring, see gitlab-foss#26481.
stages_query = statuses
.group('stage').select(:stage).order('max(stage_idx)')
status_sql = statuses.latest.where('stage=sg.stage').legacy_status_sql
warnings_sql = statuses.latest.select('COUNT(*)')
.where('stage=sg.stage').failed_but_allowed.to_sql
stages_with_statuses = CommitStatus.from(stages_query, :sg)
.pluck('sg.stage', status_sql, "(#{warnings_sql})")
stages_with_statuses.map do |stage|
Ci::LegacyStage.new(self, Hash[%i[name status warnings].zip(stage)])
end
def legacy_stages_using_composite_status
stages = Gitlab::Ci::Status::GroupedStatuses
.new(statuses.latest, :stage, :stage_idx)
.group(:stage, :stage_idx)
......@@ -400,6 +415,13 @@ module Ci
name: stage[:stage],
status: stage[:status],
warnings: stage[:warnings])
end
def legacy_stages
if Feature.enabled?(:ci_composite_status, default_enabled: true)
legacy_stages_using_composite_status
else
legacy_status_using_sql
end
end
......@@ -633,7 +655,8 @@ module Ci
def update_status
retry_optimistic_lock(self) do
case latest_builds_status.to_s
new_status = latest_builds_status.to_s
case new_status
when 'created' then nil
when 'preparing' then prepare
when 'pending' then enqueue
......@@ -646,7 +669,7 @@ module Ci
when 'scheduled' then delay
else
raise HasStatus::UnknownStatusError,
"Unknown status `#{latest_builds_status}`"
"Unknown status `#{new_status}`"
end
end
end
......
......@@ -78,7 +78,8 @@ module Ci
def update_status
retry_optimistic_lock(self) do
case latest_stage_status
new_status = latest_stage_status.to_s
case new_status
when 'created' then nil
when 'preparing' then prepare
when 'pending' then enqueue
......@@ -91,7 +92,7 @@ module Ci
when 'skipped', nil then skip
else
raise HasStatus::UnknownStatusError,
"Unknown status `#{statuses.latest.status}`"
"Unknown status `#{new_status}`"
end
end
end
......
......@@ -59,9 +59,13 @@ module HasStatus
end
def slow_composite_status
Gitlab::Ci::Status::GroupedStatuses
.new(all)
.one[:status]
if Feature.enabled?(:ci_composite_status, default_enabled: true)
Gitlab::Ci::Status::GroupedStatuses
.new(all)
.one[:status]
else
legacy_status
end
end
def started_at
......
......@@ -15,7 +15,9 @@ module Gitlab
def status
case
when none? || only_of?(:skipped)
when none?
:skipped
when only_of?(:skipped)
warnings? ? :success : :skipped
when only_of?(:success, :skipped)
:success
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment